2011-02-23 82 views
0

我想停止程序流程,直到收到來自子窗口的輸入。對於父窗口java腳本中的父子窗口

代碼:

<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

你幾乎可以肯定沒有。像這樣同步等待通常是Web應用程序中的一個壞主意。

你可以用jQuery做一個模態對話框;這聽起來像你想要的。像你這樣的新窗口被設計成大部分是獨立的實體。