js 父窗口控制子窗口的行為-打開,關(guān)閉,重定位,回復(fù)
更新時間:2010年04月20日 18:07:50 作者:
技術(shù)要點可以利用windows的open和closed來對子窗口的控制,需要父窗口和子窗口之間進行互動。
測試的時候,注意當(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)文章
微信小程序表單驗證插件WxValidate的二次封裝功能(終極版)
這篇文章主要介紹了微信小程序表單驗證插件WxValidate的二次封裝功能(終極版),文中給大家提到了最終版與前面2版的不同點,需要的朋友可以參考下2019-09-09基于JavaScript實現(xiàn)高德地圖和百度地圖提取行政區(qū)邊界經(jīng)緯度坐標
本文給大家介紹javascript實現(xiàn)高德地圖和百度地圖提取行政區(qū)邊界經(jīng)緯度坐標的相關(guān)知識,本文實用性非常高,代碼簡單易懂,需要的朋友參考下吧2016-01-01JS基于設(shè)計模式中的單例模式(Singleton)實現(xiàn)封裝對數(shù)據(jù)增刪改查功能
這篇文章主要介紹了JS基于設(shè)計模式中的單例模式(Singleton)實現(xiàn)封裝對數(shù)據(jù)增刪改查功能.結(jié)合實例形式分析了javascript基于單例模式結(jié)合ajax針對數(shù)據(jù)庫進行增刪改查的相關(guān)操作技巧,需要的朋友可以參考下2018-02-02