我试图在子窗口中提醒一个变量(来自父窗口)。我在这里查看了解决方案,但它们对我不起作用,我认为我的代码中缺少某些内容或错误。当我运行代码时,错误控制台告诉我 window.opener 为空。我试过 parent.window.opener... 这也说同样的话。
父.htm:
<head>
<script type="text/javascript">
var testtest = "hi";
function reply_click(clicked_id){
document.getElementById('resultspanel').style.display = 'none';
document.getElementById('mainpanel').style.display = 'none';
var buttonid = clicked_id;
window.buttonid = buttonid; //makes it global
alert(buttonid);
switch(clicked_id) {
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "10": $('#mainpanel').load("info.htm");document.getElementById('mainpanel').style.display = 'block'; break;
}
//$('#mydiv').load('newPage.html', {field1: 'value1', ...});
}
</script>
</head>
孩子.htm
<head>
<script type="text/javascript">
function test(){
//alert(this.parentNode.id);
//alert(parent.window.opener.testtest);
//window.opener.alert(testtest);
var myvar = window.opener.buttonid;
alert(myvar);
}
</script>
</head>
<body>
<p>INFORMATION</p>
<div id = "test" style = "border-style:solid; height:10%; width:10%;" onClick = "test();" >DIV</div>
</body>