js 父窗口控制子窗口的行為-打開,關(guān)閉,重定位,回復(fù)
更新時(shí)間:2010年04月20日 18:07:50 作者:
技術(shù)要點(diǎn)可以利用windows的open和closed來對子窗口的控制,需要父窗口和子窗口之間進(jìn)行互動(dòng)。
測試的時(shí)候,注意當(dāng)前目錄中,有代碼中的html文件。
<!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窗口打開</title>
<script language="javascript">
var winID = null;
//打開窗口
function openWindow()
{
winID = window.open("windowTime.html","JavaScript");
}
//關(guān)閉窗口
function closeWindow()
{
if(winID && winID.open && !winID.closed)
{
winID.close();
}
}
//更改URL網(wǎng)址
function changeURL(newURL)
{
if(winID && winID.open && !winID.closed)
winID.location.href = newURL;
}
</script>
</head>
<body onunload="closeWindow()">
<h2>窗口的打開與關(guān)閉
<hr />
<form>
<input type="button" value="打開窗口" onclick="openWindow()" />
<input type="button" value="關(guān)閉窗口" onclick="closeWindow()" />
<input type="button" value="顯示性的url" onclick="changeURL('yes.html')" />
<input type="button" value="重新新窗口的URL" onclick="changeURL('displayClock.html')" />
</body>
</html>
復(fù)制代碼 代碼如下:
<!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窗口打開</title>
<script language="javascript">
var winID = null;
//打開窗口
function openWindow()
{
winID = window.open("windowTime.html","JavaScript");
}
//關(guān)閉窗口
function closeWindow()
{
if(winID && winID.open && !winID.closed)
{
winID.close();
}
}
//更改URL網(wǎng)址
function changeURL(newURL)
{
if(winID && winID.open && !winID.closed)
winID.location.href = newURL;
}
</script>
</head>
<body onunload="closeWindow()">
<h2>窗口的打開與關(guān)閉
<hr />
<form>
<input type="button" value="打開窗口" onclick="openWindow()" />
<input type="button" value="關(guān)閉窗口" onclick="closeWindow()" />
<input type="button" value="顯示性的url" onclick="changeURL('yes.html')" />
<input type="button" value="重新新窗口的URL" onclick="changeURL('displayClock.html')" />
</body>
</html>
相關(guān)文章
微信小程序表單驗(yàn)證插件WxValidate的二次封裝功能(終極版)
這篇文章主要介紹了微信小程序表單驗(yàn)證插件WxValidate的二次封裝功能(終極版),文中給大家提到了最終版與前面2版的不同點(diǎn),需要的朋友可以參考下2019-09-09webpack實(shí)現(xiàn)靜態(tài)資源緩存的方法
本文主要介紹了webpack實(shí)現(xiàn)靜態(tài)資源緩存的方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08基于JavaScript實(shí)現(xiàn)高德地圖和百度地圖提取行政區(qū)邊界經(jīng)緯度坐標(biāo)
本文給大家介紹javascript實(shí)現(xiàn)高德地圖和百度地圖提取行政區(qū)邊界經(jīng)緯度坐標(biāo)的相關(guān)知識(shí),本文實(shí)用性非常高,代碼簡單易懂,需要的朋友參考下吧2016-01-01JS基于設(shè)計(jì)模式中的單例模式(Singleton)實(shí)現(xiàn)封裝對數(shù)據(jù)增刪改查功能
這篇文章主要介紹了JS基于設(shè)計(jì)模式中的單例模式(Singleton)實(shí)現(xiàn)封裝對數(shù)據(jù)增刪改查功能.結(jié)合實(shí)例形式分析了javascript基于單例模式結(jié)合ajax針對數(shù)據(jù)庫進(jìn)行增刪改查的相關(guān)操作技巧,需要的朋友可以參考下2018-02-02