Javascript implements the method of passing parameters to a browser window

  • 2020-03-30 03:52:24
  • OfStack

a.html


<html> 
<head> 
<title> The main page </title> 
<script language="javascript" type="text/javascript"> 
function OpenNew() 
{ 
var im=new IDAndMethod(); 
im.ID=document.getElementById("txtID").value; 
window.showModalDialog("ddd.html",im,""); 
} 
function IDAndMethod() 
{ 
this.ID="ddd"; 
this.Method=SetTxt; 
} 
function SetTxt(str) 
{ 
document.getElementById("txtID").value=str; 
} 
</script> 
</head> 
<body> 
<form action="#"> 
<input id="txtID" style="width:400px" type="text" value="XXX ! I'm gonna type in here ID!" /><br /> 
<input type="button" value=" Open a new window " onclick="OpenNew()" /> 
</form> 
</body> 
</html>

 b.html


<html> 
<head> 
<title> The main page </title> 
<script language="javascript" type="text/javascript"> 
var im; 
function Load() 
{ 
im=window.dialogArguments; 
if(im.ID=="XXX ! I'm gonna type in here ID") 
document.getElementById("txtID1").value=" You don't type in anything !"; 
else 
document.getElementById("txtID1").value=im.ID; 
} 
function Set() 
{ 
im.Method(document.getElementById("txtID1").value); 
} 
</script> 
</head> 
<body onload="Load()"> 
<form action="#"> 
<input id="txtID1" style="width:400px" type="text" value="ddd" /><br /> 
<input type="button" value=" To transfer data " onclick="Set()" /> 
</form> 
</body> 
</html>

Related articles: