SoFunction
Updated on 2025-04-14

javascript showModalDialog value transfer and FireFox parent-child window value transfer example page 2/2


Below is a test code posted by friends online, you can test it.
Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Main Page</title>
</head>
<script type="text/javascript"><!--
//Pass the array
function check(){
var mxh1 = new Array("mxh","net_lover","Mencius Chapter E")
("",mxh1,"unadorned:0;scroll:0;status:false;dialogWidth:380px;dialogHeight:200px");
}
//Transfer the object
function check1(){
var obj = new Object();
="zhangsan";
=2;
="Male";
("",obj,"unadorned:0;scroll:0;status:false;dialogWidth:380px;dialogHeight:200px");
}
// --></script>
<body onload="check1();">
</body>
</html>

source code:
Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Get the value of the main page</title>
</head>
<body>
    script type="text/javascript"><!--
//Passing array method
        //var test = dialogArguments;
        //alert(test[0]);
        //alert(test[1]);
        //alert(test[2]);
//Transfer method
        var obj = dialogArguments;
        alert();
        alert();
        alert();

    
// --></script>
    <input type="text" />
</body>
</html>

showModalDialog value transmission and refresh
Use example of showModalDialog, the parent window passes the value to the child window, the child window sets the value of the parent window, and the value is returned to the parent window when the child window is closed.

Copy the codeThe code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<script language="javascript">
<!--
function openChild(){
var k = ("",window,"dialogWidth:335px;status:no;dialogHeight:300px");
if(k != null)
("txt11").value = k;
}
//-->
</script>
</HEAD>
<BODY>
<FONT face="Song style"></FONT>
<br>
The value passed to the parent window:<input type="text" value="3333333333" name="txt9"><br>
Returned value:<input type="text" name="txt11"><br>
Value set by child window:<input type="text" name="txt10"><br>
<input onclick="openChild()" type="button" value="openChild" name="Button1">
</BODY>
</HTML>


Copy the codeThe code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY>
<FONT face="Song style"></FONT>
<br>
The value passed from the parent window:<input type="text" name="txt0"><br>
Enter the value of the parent window to be set: <input type="text" name="txt1"><input onclick="setFather()" type="button" value="Set the value of the parent window" name="Button1"><br>
Enter the returned value: <input type="text" name="txt2"><input onclick="retrunValue()" type="button" value="Close Cut Return Value" name="Button2">
<input onclick="" type="button" value="Close Refresh Parent Window" name="Button3">
<script language="javascript">
<!--
var k=;
//Get the value passed by the parent window
if(k!=null)
{
("txt0").value = ("txt9").value;
}
//Set the value of the parent window
function setFather()
{
("txt10").value = ("txt1").value
}
//Set the value returned to the parent window
function retrunValue()
{
var s = ("txt2").value;
=s;
();
}
//-->
</script>
</BODY>
</HTML>

illustrate:
Since showModalDialog cache is serious, the following is the setting to cancel the client cache in the child window. You can also cancel the cache on the server side, refer to:
My next post.
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
(II) The following is an example of closing the refresh parent window

Copy the codeThe code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
<!--
function openChild()
{
var k = ("",window,"dialogWidth:335px;status:no;dialogHeight:300px");
if(k == 1)//Judge whether to refresh
{
alert('refresh');
();
}
}
//-->
</script>
</HEAD>
<BODY>
<br>
Value passed to parent window:<input type="text" value="33333333333" NAME="txt9"><br>
<input type="button" value="openChild" onclick="openChild()" ID="Button1" NAME="Button1">
</BODY>
</HTML>


Copy the codeThe code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META content="EditPlus" name="Generator">
<META content="" name="Author">
<META content="" name="Keywords">
<META content="" name="Description">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY>
<FONT face="Song style"></FONT>
<br>
The value passed from the parent window:<input type="text" name="txt0"><br>
<input onclick="winClose(1)" type="button" value="Close refresh parent window" name="Button1">
<input onclick="winClose(0)" type="button" value="Close not refresh the parent window" name="Button2">
<script language="javascript">
<!--
var k=;
//Get the value passed by the parent window
if(k!=null)
{
("txt0").value = ("txt9").value;
}
//Close the window to return the parameters of whether to refresh.
function winClose(isRefrash)
{
=isRefrash;
();
}
//-->
</script>
</BODY>
</HTML>

illustrate
1. The following is to cancel the client cache:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
You can also cancel the cache on the server side, refer to my next article
2. The explanation to the parent window can also be passed in the way of ?id=1.
3. If the parent window is not refreshed, you can set it in the parent window in this way.
<script>
("",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4. If you want to submit a page in the child window, you must add it: so that the new window will not be opened.
<head>
<base target="_self">
</HEAD>
Previous page12Read the full text