使用JavaScript location.reload方法刷新網(wǎng)頁。當(dāng)用戶點(diǎn)擊一個鏈接此代碼可以自動在一個事件調(diào)用。
如果想使用鼠標(biāo)點(diǎn)擊刷新網(wǎng)頁,可以用下面的代碼:
<a href="javascript:location.reload(true)">Refresh Page</a>
要了解它更好的辦法,可以刷新頁面
自動刷新:
還可以使用JavaScript后自動給定時間段,以刷新頁面。以下是每5秒后會刷新此頁面的例子??梢愿淖冞@個時候按您的要求。
<html>
<head>
<script type="text/JavaScript">
<!--
function AutoRefresh( t ) {
setTimeout("location.reload(true);", t);
}
// -->
</script>
</head>
<body onload="JavaScript:AutoRefresh(5000);">
<p>This page will refresh every 5 seconds.</p>
</body>
</html>
這里的 setTimeout()是一個內(nèi)置的JavaScript函數(shù),可用于給定的時間間隔之后執(zhí)行另一個函數(shù)。
javascript 強(qiáng)制刷新頁面的實(shí)現(xiàn)代碼
Javascript刷新頁面的幾種方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
自動刷新頁面的方法:
1.頁面自動刷新:把如下代碼加入<head>區(qū)域中
其中20指每隔20秒刷新一次頁面.
2.頁面自動跳轉(zhuǎn):把如下代碼加入<head>區(qū)域中
<meta http-equiv="refresh" content="20;url=http://www.15014759268.cn">
其中20指隔20秒后跳轉(zhuǎn)到http://www.15014759268.cn頁面
3.頁面自動刷新js版
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
1. this.response.write("<script>opener.location.reload();</script>");
2. this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");
3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的頁.asp'');</script>")
JS刷新框架的腳本語句 //如何刷新包含該框架的頁面用
parent.location.reload();
//子窗口刷新父窗口
self.opener.location.reload();
( 或 <a href="javascript:opener.location.reload()">刷新</a> ) //如何刷新另一個框架的頁面用
parent.otherFrameID.location.reload();
<body onload="opener.location.reload()"> 開窗時刷新
<body onUnload="opener.location.reload()"> 關(guān)閉時刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
//跳出頁面
if (top.location !== self.location) {
top.location=self.location;
}
javascript 頁面只自動刷新一次
代碼如下:
function reurl(){
url = location.href; //把當(dāng)前頁面的地址賦給變量 url
var times = url.split("?"); //分切變量 url 分隔符號為 "?"
if(times[1] != 1){ //如果?后的值不等于1表示沒有刷新
url += "?1"; //把變量 url 的值加入 ?1
self.location.replace(url); //刷新頁面
}
}
onload=reurl
原理
充分利用地址欄可帶參數(shù)的選項(xiàng),用腳本來取得頁面間的傳遞參數(shù),并不需要后臺程序的支持。
更多建議: