我可以写些东西给一个像这样的
window.frames[0].document.write(something);
但我正试图从同一域中打开的窗口向iframe写一些东西。我不知道该怎么瞄准那个目标。我试过这样的方法:
window.opener.document.getElementById("iframe").write(something);
或
window.opener.frames[0].document.write(something);
但那不管用。关于我想做什么有什么想法或问题吗?
* iframe在父窗口上。我试着从打开的窗口瞄准
发布于 2013-09-03 17:02:54
您需要使用iframe的contentWindow
属性。尝尝这个。
父页
<iframe id="ifr"></iframe>
<button onclick="window.open('child.html')">Open Window</button>
Child.html页面
<button onclick="writeToParentIframe()">Write to Parent Iframe</button>
<script>
function writeToParentIframe() {
opener.document.getElementById("ifr").contentWindow.document.write("<h1>Hello World</h1>")
}
</script>
https://stackoverflow.com/questions/18594046
复制相似问题