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.
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.
Share Improve this question asked Aug 31, 2009 at 11:09 Benoît PointetBenoît Pointet 8982 gold badges11 silver badges23 bronze badges 4- 1 can you instanciate document object already inside iframe? – Eldar Djafarov Commented Aug 31, 2009 at 11:14
- I have no clue what in the world your question is here. Wondering if I am the only one. – epascarello Commented Aug 31, 2009 at 11:34
- Djko : well that was the last solution I was thinking of: instanciating the object inside the iframe and then modify it, finally inject iframe in main document. I wanted to make sure that I was not missing something. – Benoît Pointet Commented Aug 31, 2009 at 11:45
- epascarello : in other words : to put a document in a window you have to give the url for it, or when your document is already locally in a string, then you can write into the window this string. But when your document is a document object, loaded "in the background" through some XmlHTTPRequest and transformed, linked, ..., then HOW CAN YOU INJECT IT INTO A WINDOW OR IFRAME ? – Benoît Pointet Commented Aug 31, 2009 at 11:48
1 Answer
Reset to default 7Try 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/en/DOM/document.importNode
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340974a4623324.html
评论列表(0条)