javascript中的父子窗口

时间:2011-02-23 11:04:25

标签: javascript

我想停止程序流程,直到我从子窗口收到输入。

父窗口的代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>MainPage</title>
<SCRIPT LANGUAGE="JavaScript">

function openpage(){
window.open("ok.htm","Warning",'fullscreen=0,height=150,width=300,left=500,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=200');

//this the place i want my program to wait till i get any  input that is any change in document.fm.w.value form my child window///////
alert(document.fm.w.value);/// alert should contain the new value acorrding to selection of button in child window////

 }
</SCRIPT>
</head>
<body>
<form name="fm"> 
<input type="hidden" size="40" id="w" value="wwww">
<input type="button" value= "press" id="q" name= "q" onclick= "openpage();">
</form>
</body>
</html>

子窗口代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Warning</title>
<SCRIPT LANGUAGE="JavaScript">

function ReturnToMainPage1() {
window.opener.document.fm.w.value = "X"
//self.close();
}
function ReturnToMainPage2() {
window.opener.document.fm.w.value = "O"
self.close();
}

</SCRIPT>
</head>
<body>
<form name="fm"> 
<table id="MessageTable" width="100%">
    <tr>
        <td align="center">
        <input type="button" value= "OK" id="Latest_Version" onclick= "ReturnToMainPage1();"></td>
        <td>View Latest Released Version</td>
    </tr>
    <tr>
        <td align="center"><input type="button" value= "OK" id="Older_Version" onclick= "ReturnToMainPage2();"></td>
        <td>Continue Viewing Obsolete Version</td>
    </tr>

</table>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

你几乎肯定不会。像这样同步等待通常是网络应用程序中的一个坏主意。

你可以用jQuery创建一个模态对话框;这听起来像你想要的。像你这样的新窗口在很大程度上是一个独立的实体。