我对 window.opener 函数(JS)有疑问:
我创建了 3 个简单的页面来模拟我的问题:
测试.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 中,内容是:“从弹出窗口的第一页测试”。
错误信息:
window.opener.document.getElementById(...) is null