Alvaro Alvaro -5 years ago 108
Javascript Question

Append a whole page to an iframe

I would like to append a whole page (with

elements) inside an existent empty iframe.

Is it possible at all?

As far as I've seen they always append the content to some child element in the iframe, such as


But I'm trying the append a whole page, with styles, head and so on, so I would need to append it to the document level.
Something like this:

//not working

Answer Source

You could use document write() method, like this:

var iframeDoc = $('iframe')[0].contentDocument; // jQuery is just for the example of course

Where data is a full valid page source string, including DOCTYPE, HEAD, etc...


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download