如何替换窗口/iframe的文档对象 [英] howto replace document object of a window/iframe

查看:200
本文介绍了如何替换窗口/iframe的文档对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iframe窗口中注入我之前实例化的文档对象,并且我无法将其序列化为字符串或远程url(这些是先前stackoverflow帖子中提出的解决方案),因为此文档对象的元素已绑定到我代码中的其他对象.

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.

我该怎么办?

谢谢, b.

推荐答案

尝试使用 importNode :

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
);

请参见 https://developer.mozilla.org/en/DOM/document.importNode

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

这篇关于如何替换窗口/iframe的文档对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆