Javascript刷新框架及頁(yè)麵的方(fāng)法總集
先來(lái)看一個簡單的(de)例子:
下麵(miàn)以三個頁麵分別(bié)命(mìng)名(míng)為frame.html、top.html、bottom.html為例來具體說明如何做。
frame.html 由上(top.html)下(bottom.html)兩個頁麵組成,代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> frame </TITLE>
</HEAD>
<frameset rows="50%,50%">
<frame name=top src="top.html">
<frame name=bottom src="bottom.html">
</frameset>
</HTML>
現在假(jiǎ)設top.html (即上麵的頁麵(miàn)) 有七個button來實現對bottom.html (即下麵的頁麵(miàn)) 的刷新,可以用以下七種(zhǒng)語句,哪個好用自己看著辦了。
語句1. window.parent.frames[1].locations.reload();
語句2. window.parent.frames.bottom.locations.reload();
語句3. window.parent.frames["bottom"].locations.reload();
語句(jù)4. window.parent.frames.item(1).locations.reload();
語句5. window.parent.frames.item('bottom').locations.reload();
語句6. window.parent.bottom.locations.reload();
語(yǔ)句7. window.parent['bottom'].locations.reload();
top.html 頁麵(miàn)的代碼(mǎ)如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<input type=button value="刷新1" onclick="window.parent.frames[1].locations.reload()"><br>
<input type=button value="刷新2" onclick="window.parent.frames.bottom.locations.reload()"><br>
<input type=button value="刷新3" onclick="window.parent.frames['bottom'].locations.reload()"><br>
<input type=button value="刷(shuā)新4" onclick="window.parent.frames.item(1).locations.reload()"><br>
<input type=button value="刷新5" onclick="window.parent.frames.item('bottom').locations.reload()"><br>
<input type=button value="刷新6" onclick="window.parent.bottom.locations.reload()"><br>
<input type=button value="刷(shuā)新7" onclick="window.parent['bottom'].locations.reload()"><br>
</BODY>
</HTML>
下麵(miàn)是bottom.html頁麵源代碼,為了證明下方頁麵的確被刷新了,在裝(zhuāng)載完頁麵(miàn)彈出一個對話框。
bottom.html 頁麵的代碼如(rú)下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<BODY onload="alert('我被加載了!')">
<h1>This is the content in bottom.html.</h1>
</BODY>
</HTML>
解釋一下:
1.window指代的是當前頁麵,例如對於此例(lì)它指的是top.html頁麵。
2.parent指的是當前頁麵的父頁麵,也就(jiù)是包含它(tā)的框架頁(yè)麵。例(lì)如對於(yú)此例它指的(de)是framedemo.html。
3.frames是window對象,是一個數組。代表著該框(kuàng)架內所有子頁麵。
4.item是方法。返(fǎn)回數組裏麵的元素。
5.如果(guǒ)子頁麵也是個框架頁麵,裏(lǐ)麵還(hái)是其它的子頁麵,那麽上麵的有些方法可能不行。
附(fù):
Javascript刷新頁麵的幾種方法:
1 history.go(0)
2 locations.reload()
3 locations=locations
4 locations.assign(locations)
5 document.execCommand('Refresh')
6 window.navigate(locations)
7 locations.replace(locations)
8 document.URL=locations.href
自動刷新頁麵的方法:
1.頁麵自動刷新:把如下代碼加入<head>區域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒(miǎo)刷新一次頁麵.
2.頁麵自動跳轉:把如下代碼加入(rù)<head>區域中
<meta http-equiv="refresh" content="20;url=http://www.ynaad.com">
其(qí)中(zhōng)20指(zhǐ)隔20秒後跳轉到http://www.ynaad.com頁麵
3.頁麵自動刷新js版
<script language="JavaScript">
function myrefresh()
{
window.locations.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷(shuā)新一次(cì)
</script>
ASP.NET如何輸出刷新父窗口腳本語句(jù)
1. this.response.write("<script>opener.locations.reload();</script>");
2. this.response.write("<script>opener.window.locations.href = opener.window.locations.href;</script>");
3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的頁.asp'');</script>")
JS刷新框架的腳本語句
//如(rú)何(hé)刷新包含該框架的頁麵用
<script language=JavaScript>
parent.locations.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.locations.reload();
</script>
( 或 <a href="javascript:opener.locations.reload()">刷新</a> )
//如(rú)何刷新另一個框架的頁麵用
<script language=JavaScript>
parent.另一FrameID.locations.reload();
</script>
如果想關閉窗口時刷新或者想開窗時刷新的話,在(zài)<body>中調用以下語句即可。
<body onload="opener.locations.reload()"> 開窗時刷新
<body onUnload="opener.locations.reload()"> 關閉(bì)時刷新(xīn)
<script language="javascript">
window.opener.document.locations.reload()
</script>
1.window指代的是當前頁麵,例如對於此例它指的(de)是top.html頁麵
window 對象是整個BOM(browser object mode)的核心,所有對象和集合都和window關聯.這樣window對象就表示整個瀏覽器窗口了(le)
3.frames是window對象,是(shì)一個數組。代表(biǎo)著該框架內所(suǒ)有(yǒu)子頁麵。
如(rú)果頁麵裏有框架集合,那麽每個框架都由它自己的window對象表(biǎo)示並存(cún)放在frames集合中.
Index.htm 頁麵(miàn):
<html>
<head>
<title>框(kuàng)架集與框架</title>
</head>
<frameset rows="80px,*">
<frame name="topframe" src="Top.htm">
<frameset cols="180px,*">
<frame name="meframe" src="Menu.htm">
<frameset rows="*,60px">
<frame name="dcframe" src="DefaultContent.htm">
<frame name="buframe" src="Bottom.htm">
</frameset>
</frameset>
</frameset><noframes></noframes>
</html>
Menu.htm 頁麵:
<p>
<a href="News_01.htm" target="dcframe">新聞標題</a>
關鍵詞:Javascript
閱讀本文後您有什麽感想? 已有 人給出評(píng)價!
- 3
- 0
- 0
- 0
- 0
- 0