在父窗口中控制子窗口行为(打开、关闭等)的代码

发布时间:2020-05-08编辑:脚本学堂
在本文介绍的代码中,我们使用windows的open和closed控制子窗口的打开与关闭,有需要的朋友,不妨参考下了。

完整代码。
 

复制代码 代码示例:
<!DOCTYPE html 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>windows父窗口中控制子窗口的行为_www.jb200.com</title>
<script language="javascript">
var winID = null;
//打开窗口
function openWindow()
{
winID = window.open("windowTime.html","JavaScript");
}
//关闭窗口
function closeWindow()
{
if(winID && winID.open && !winID.closed)
{
winID.close();
}
}
//更改URL网址
function changeURL(newURL)
{
if(winID && winID.open && !winID.closed)
winID.location.href = newURL;
}
</script>
</head>
<body onunload="closeWindow()">
窗口的打开与关闭
<hr />
<form>
<input type="button" value="打开窗口" onclick="openWindow()" />
<input type="button" value="关闭窗口" onclick="closeWindow()" />
<input type="button" value="显示性URL" onclick="changeURL('脚本学堂_url.html')" />
<input type="button" value="重建新窗口的URL" onclick="changeURL('脚本学堂_display.html')" />
</body>
</html>