我有这样的东西:
<!doctype html>
<html>
<body>
<iframe id="someFrame"></iframe>
</body>
</html>
我想使用 jQuery 编写元素,这样完整的等效 HTML 将如下所示:
<!doctype html>
<html>
<body>
<iframe id="someFrame">
<!-- inside the iframe's content -->
<!-- <html><body> -->
<div>A</div>
<div>B</div>
<div>C</div>
<!-- </body></html> -->
</iframe>
</body>
</html>
或者,任何普通的旧 Javascript 都可以。
谢谢。
编辑:经过更多的研究,我似乎正在寻找 iframe 的 contentDocument 属性的 IE 等价物。 “contentDocument”是FF支持的W3C标准,但IE不支持。 (惊喜惊喜)
最佳答案
你可以两者都做,你只需要不同的目标:
var ifrm = document.getElementById('myIframe');
ifrm = ifrm.contentWindow || ifrm.contentDocument.document || ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write('Hello World!');
ifrm.document.close();
关于javascript - 使用 Javascript 或 jQuery 将元素写入子 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/997986/