当父窗口转到switch和case语句中的不同case时,我试图打开子弹出窗口,然后当父窗口转到另一个不同的情况时关闭该子窗口:
case "1":
$nextDecision = "
<form action=\"index.php\" method=\"get\">
<input type=\"radio\" name=\"choice\" value=\"val1\">message<br>
<input type=\"submit\">
</form>";
?>
<script language="JavaScript" type="text/javascript" src="javascripts.js"></script>
<body onload="javascript:openWin()"></body>
<?php
break;
case "2":
$nextDecision = "
<form action=\"index.php\" method=\"get\">
<input type=\"radio\" name=\"choice\" value=\"val2\">message<br>
<input type=\"submit\">
</form>";
?>
<body onload="javascript:closeWin()"></body>
<?php
break;
javascripts.js:
function openWin() {
myWindow=window.open("file/popup.html", "name", "width=200, height=100");
}
function closeWin() {
myWindow.close();
}
答案 0 :(得分:0)
您尝试在身体负载上关闭子窗口,该窗口无法访问子窗口。尝试在父窗口重新加载之前关闭它..
function closeWin() {
document.getElementById('choice').value='val2';
myWindow.close();
}
<form action=\"index.php\" method=\"get\">
<input type=\"radio\" id=\"choice\" name=\"choice\" onsubmit="closeWin()" value=\"val2\">message<br>
<input type=\"submit\" >
</form>";