Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto replace document object of a window/iframe

I need to inject in an iframe window a document object that I instanciated previously, and I cannot serialize it into a string or a remote url (those are solutions proposed on previous stackoverflow posts), because elements of this document objects are bound to other objects in my code.

How can I do it ?

thanks, b.

like image 447
Benoît Pointet Avatar asked Aug 31 '09 11:08

Benoît Pointet


1 Answers

Try using importNode:

/* Change these: */
var documentToCopy = document,
    iframeDocument = iframe.contentWindow.document;

/* Replace current document-element (<html>) with the new one: */
iframeDocument.replaceChild(
    iframeDocument.importNode(documentToCopy.documentElement, true),
    iframeDocument.documentElement
);

See https://developer.mozilla.org/en/DOM/document.importNode

like image 136
James Avatar answered Sep 28 '22 05:09

James