js 父窗口控制子窗口的行為-打開,關(guān)閉,重定位,回復(fù)
更新時(shí)間:2010年04月20日 18:07:50 作者:
技術(shù)要點(diǎn)可以利用windows的open和closed來對(duì)子窗口的控制,需要父窗口和子窗口之間進(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)文章
JS產(chǎn)生隨機(jī)數(shù)的幾個(gè)用法詳解
下面小編就為大家?guī)硪黄狫S產(chǎn)生隨機(jī)數(shù)的幾個(gè)用法詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06
Layui給數(shù)據(jù)表格動(dòng)態(tài)添加一行并跳轉(zhuǎn)到添加行所在頁的方法
今天小編就為大家分享一篇Layui給數(shù)據(jù)表格動(dòng)態(tài)添加一行并跳轉(zhuǎn)到添加行所在頁的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08
關(guān)于ES6新特性最常用的知識(shí)點(diǎn)匯總
日常開發(fā)中寫的 JavaScript 代碼,會(huì)用到ES6的部分新特性,所以下面這篇文章主要給大家介紹了關(guān)于ES6新特性最常用的知識(shí)點(diǎn),文章總結(jié)的非常全面,需要的朋友可以參考下2021-11-11
JavaScript Rxjs mergeMap 的使用場合
這篇文章主要介紹了JavaScript Rxjs mergeMap 的使用場合,mergeMap 接收一個(gè)函數(shù)作為輸入?yún)?shù),這個(gè)函數(shù)的輸入?yún)?shù)就是通過 pipe 鏈接 mergeMap 的 Observable 里包含的元素2022-07-07
JS實(shí)現(xiàn)同一DOM元素上onClick事件與onDblClick事件并存的解決方法
這篇文章主要介紹了JS實(shí)現(xiàn)同一DOM元素上onClick事件與onDblClick事件并存的解決方法,結(jié)合實(shí)例形式分析了javascript通過針對(duì)單擊onclick事件增加定時(shí)器進(jìn)行onClick事件與onDblClick事件的區(qū)別判定操作,需要的朋友可以參考下2018-06-06
uniapp中scroll-view基礎(chǔ)用法示例代碼
我們在項(xiàng)目中往往都能遇到實(shí)現(xiàn)左右滑動(dòng)跟上下滑動(dòng)的需求,下面這篇文章主要給大家介紹了關(guān)于uniapp中scroll-view基礎(chǔ)用法的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11

