以下为openerwindow.htm
<html>
<head>
<script language="JavaScript" type="text/javascript">
var newWindow;
function butOpenWin_onclick()
{
var winTop=(screen.height/2)-125;
var winLeft=(screen.width/2)-125;
var windowFeatures="width=250,height=250";
windowFeatures=windowFeatures+"left="+winLeft+",";
windowFeatures=windowFeatures+"top="+winTop;
newWindow=window.open("newWindow.htm","myWindow",windowFeatures);
}
function butGetText_onclick()
{
if(typeof(newWindow)=="undefined" || newWindow.closed==true)
{
alert("No window is open");
}
else
{
document.form1.text1.value=newWindow.document.form1.text1.value;
}
}
function window_onunload()
{
if(typeof(newWindow)!="undefined" && newWindow.closed==false)
{
newWindow.close();
}
}
</script>
</head>
<body οnunlοad="window_onunload()">
<form name=form1>
<input type="button" value="Open newWindow" name=butOpenWin οnclick="butOpenWin_onclick()">
<br><br> NewWindow's Text <br>
<input type="text" name=text1>
<br>
<input type="button" value="Get Text" name=butGetText οnclick="return butGetText_onclick()">
</form>
</body>
</html>
以下为newWindow.htm
<html>
<head>
<script language="JavaScript" type="text/javascript">
function butGetText_onclick()
{
document.form1.text1.value=window.opener.document.form1.text1.value;
}
</script>
</head>
<body>
<form name=form1>
Opener window's text
<br>
<input type="text" name=text1>
<br>
<input type="button" value="Get Text" name=butGetText
language="JavaScript" type="text/javascript" οnclick="butGetText_onclick()">
</form>
</body>
</html>