admin管理员组文章数量:1420929
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
本文标签: javascripthowto replace document object of a windowiframeStack Overflow
版权声明:本文标题:javascript - howto replace document object of a windowiframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745340974a2654259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论