Hit*_*nds 8 javascript iframe internet-explorer data-uri
我需要在沙盒视图中显示内容,主要是一个完整的html文档(<html>...</html>).我正在使用带有src datauri的沙盒iframe .
var
iframe = document.createElement('iframe'),
content = '<html><head></head><body><h1>Hello</h1></body></html>'
;
iframe.sandbox = '';
iframe.src = 'data:text/html;charset=utf-8,' + content;
document.body.appendChild(iframe);Run Code Online (Sandbox Code Playgroud)
不幸的是,Internet Explorer不支持...有没有解决方案/解决方法?
我的解决方案:
index.html,只是为了具有同源 iframe。function ReplaceIframeContentCtrl() {
var iframe = document.getElementById('test');
var content = "<html><head></head><body><h1>Hello</h1></body></html>";
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(content);
iframe.contentWindow.document.close();
}
document.addEventListener('DOMContentLoaded', ReplaceIframeContentCtrl);Run Code Online (Sandbox Code Playgroud)
<iframe id="test" src="/index.html"></iframe>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1384 次 |
| 最近记录: |