您的位置:首页 > 编程语言

窗口之间的脚本编程

2013-10-24 10:47 309 查看
以下为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 onunload="window_onunload()">

<form name=form1>
<input type="button" value="Open newWindow" name=butOpenWin onclick="butOpenWin_onclick()">
<br><br> NewWindow's Text <br>
<input type="text" name=text1>
<br>
<input type="button" value="Get Text" name=butGetText onclick="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" onclick="butGetText_onclick()">
</form>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: