0
我試圖動態地將HTML添加到現有頁面。我已經獲得了加載和顯示的iframe。但是iframe的「Body」沒有顯示。任何幫助?將HTML動態加載到iframe中
<html>
<head>
<script>
window.onload = function() {
var iframe = document.createElement('iframe');
var html =
'<html><head>' +
'<scr' + 'ipt src="https://localhost:44302/foo.js"></scr' + 'ipt>' +
'<scr' + 'ipt src="https://localhost:44302/bar.js"></scr' + 'ipt>' +
'</head>' +
'<body>Hi</body></html>';
iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
document.body.appendChild(iframe);
console.log('iframe.contentWindow =', iframe.contentWindow);
}
</script>
</head>
<body></body>
</html>
https://jsfiddle.net/0m5axpxx/2/
'
zer00ne