I need to display content in a sandboxed view, mostly a full html document (<html>...</html>
). I'm using a sandboxed iframe with src datauri.
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);
Unfortunately, that isn't supported in Internet Explorer... Is there any solution/workaround?
Attachments: Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.
An id on an <iframe> tag assigns an identifier to the element. The identifier must be unique across the page.
An inline frame (iframe) is a HTML element that loads another HTML page within the document. It essentially puts another webpage within the parent page. They are commonly used for advertisements, embedded videos, web analytics and interactive content.
The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document. Tip: Use CSS to style the <iframe> (see example below).
My solution:
index.html
, just for having a same origin 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);
<iframe id="test" src="/index.html"></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With