【发布时间】:2011-12-11 07:49:28
【问题描述】:
我一直在寻找一种跨浏览器的方式来以编程方式设置 IFrame 的 innerHTML。 (如http://roneiv.wordpress.com/2008/01/18/get-the-content-of-an-iframe-in-javascript-crossbrowser-solution-for-both-ie-and-firefox/)。我已经编写了一些示例代码(如下),我可以让它在 Safari 和 Chrome 中运行,但不能在 Firefox 中运行。谁能帮我弄清楚我需要做什么(以便携式方式)?
<html>
<body>
<div name=FRAME2div id=FRAME2div style="position:absolute; background-color:blue; color:black; border-color:black;border-width:0; left:100px; top:40px; width:200px; height:200px; overflow:scroll; display:block; " >
</div>
<script type="text/javascript">
document.getElementById("FRAME2div").innerHTML = '<iframe border=0 id=IFRAME2 name=IFRAME2 ></iframe>';
document.getElementById("IFRAME2").contentWindow.document.body.innerHTML = '<html><body><p>NETSCAPE</p></body></html>';
</script>
</body>
</html>
【问题讨论】:
标签: html firefox iframe innerhtml