【发布时间】:2014-08-18 08:52:35
【问题描述】:
window.opener 函数 (JS) 有问题:
我创建了 3 个简单的页面来模拟我的问题:
test.php:
<html>
<head>
</head>
<body>
<input type="button" onclick="window.open('first_page_in_popup.php', 'Popup', 'width=470,height=500');">
<input type="text" id="content" name="content" >
</body>
</html>
first_page_in_popup.php:
<html>
<head>
<script type="text/javascript" >
window.opener.document.getElementById('content').value= "Test from first page in popup";
window.open('second_page_in_popup.php', 'Popup');
</script>
</head>
<body>
</body>
</html>
second_page_in_popup.php:
<html>
<head>
<script type="text/javascript" >
window.opener.document.getElementById('content').value= "Test from second page in popup";
</script>
</head>
<body>
</body>
</html>
结果: 在 IE 中,输入字段的内容为“Test from second page in popup”。 在 Chrome 和 Firefox 中,内容为:“Test from first page in popup”。
错误信息:
window.opener.document.getElementById(...) is null
【问题讨论】:
-
这可能是一个安全限制。我经历过 Chrome 拒绝让弹出窗口获取/设置开启器的值。您是否尝试在从弹出窗口调用的主窗口中创建一个函数?
-
在 Firefox 中效果很好,我可以从弹出窗口中执行此操作并替换内容:window.opener.document.getElementById('maincontent').innerHTML = "test";你能创建一个小提琴来重现你的问题吗?
-
如果我将第二个弹出窗口重命名为“Popup2”并将第二页的代码更改为:window.opener.opener.document.getElementById('content').value="从第二页开始测试弹出窗口”;有用。但现在我必须打开弹出窗口......我只想要一个窗口。
标签: javascript google-chrome firefox window.open window.opener