<! DOCTYPEhtml PUBLIC "- / / / / W3C DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>dialog</title>
<script type="text/javascript">
   function getValue(){
      var value=window.dialogArguments;// Call dialogArguments to get the value in the parent window
	  document.forms[0].userName.value=value;
   }
   
   function closeWindow(){
        window.returnValue=document.forms[0].userName.value;
		// While closing the modal window, pass the value in the modal window to the value in the parent window using the returnValue method
		window.close();
   }
</script>
</head>
 
<body οnl&westernad="getValue()">
<form>
<input type="text" name="userName"><br /><br />
<input type="button" value="Closed" οnclick="closeWindow()">
</form>
</body>
</html>
Copy the code
<! DOCTYPEhtml PUBLIC "- / / / / W3C DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>The child window passes values to the parent window</title>
<script type="text/javascript">
   function openWindow(url){
      window.open(url,"openWindow"."height=300,width=400,menubar=yes,scrollbars=yes,left=300,top=100");
   }
   
   function openDialogWindow(url){
      var userNameValue=document.forms[0].userName.value;
	  var tempValue=window.showModalDialog(url,userNameValue,"dialogHeight=300px; dialogWidth=400px");
	  document.forms[0].userName.value=tempValue;// Assign the value returned in the modal window to the value in the parent window
   }
</script>
</head>
 
<body>
<form>
<input type="text" name="userName"><br /><br />
<input type="button" name="bName" value="Modal window" οnclick="openWindow('windowOpenTwo.html')"><br /><br />
<input type="button" name="bName" value="Modal window" οnclick="openDialogWindow('window.openDialog.html')">
</form>
</body>
</html>
Copy the code