我的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中,输入字段具有内容“在弹出窗口中从第二页测试”。 在Chrome和Firefox中,内容为:“弹出窗口中的第一页测试”。
错误讯息:
window.opener.document.getElementById(...) is null
答案 0 :(得分:1)
我通过更改页面代码&#34; first_page_in_popup.php&#34;解决了这个问题。到:
<html>
<head>
<script type="text/javascript" >
window.opener.document.getElementById('content').value= "Test from first page in popup";
window.location.href = 'second_page_in_popup.php';
</script>
</head>
<body>
<p> First Page </p>
<input type="text" id="first" name="first">
</body>
</html>
答案 1 :(得分:0)
尝试parent.window.opener
而不是window.opener
答案 2 :(得分:0)
window.opener.document.getElementById(...) is null
这意味着window.opener.document.getElementById中的内容为null或未定义 请尝试定义
content in second php as defined in first php
希望这会奏效。