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

