I\'m currently working on a form which includes some file inputs to upload pictures. There is an onchange()
event for those inputs that submits the pictures to
You can .write()
the content into the iframe document. Example:
<iframe id="FileFrame" src="about:blank"></iframe>
<script type="text/javascript">
var doc = document.getElementById('FileFrame').contentWindow.document;
doc.open();
doc.write('<html><head><title></title></head><body>Hello world.</body></html>');
doc.close();
</script>
In combination with what Guffa described, you could use the technique described in
Explanation of <script type = "text/template"> ... </script> to store the HTML document in a special script
element (see the link for an explanation on how this works). That's a lot easier than storing the HTML document in a string.
iframe now supports srcdoc which can be used to specify the HTML content of the page to show in the inline frame.
You can use data:
URL in the src
:
var html = 'Hello from <img src="http://stackoverflow.com/favicon.ico" alt="SO">';
var iframe = document.querySelector('iframe');
iframe.src = 'data:text/html,' + encodeURIComponent(html);
<iframe></iframe>
Difference between srcdoc=“…” and src=“data:text/html,…” in an iframe.
Convert HTML to data:text/html link using JavaScript.