JS頁面刷新與重新加載功能實(shí)現(xiàn)(關(guān)閉當(dāng)前窗口)
一、刷新或重新加載當(dāng)前頁面
| 序號 | 方法 |
|---|---|
| 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、reload 方法
語法: location.reload([forceGet])
參數(shù): forceGet, 可選參數(shù), 默認(rèn)為 false,從客戶端緩存里取當(dāng)前頁。true, 則以 GET 方式,從服務(wù)端取最新的頁面, 相當(dāng)于客戶端點(diǎn)擊 F5(“刷新”)
2、 replace 方法
語法: location.replace(URL)
說明: 該方法通過指定URL替換當(dāng)前緩存在歷史里(客戶端)的項(xiàng)目,因此當(dāng)使用replace方法之后,你不能通過“前進(jìn)”和“后退”來訪問已經(jīng)被替換的URL。 通常使用location.reload() 或者是 history.go(0) 來刷新當(dāng)前頁面,此方法類似點(diǎn)F5刷新,所以當(dāng)method=”post”時,因?yàn)镾ession的安全保護(hù)機(jī)制,會出現(xiàn)“網(wǎng)頁過期”的提示。
例: location.replace(location.href);其中l(wèi)ocation.href為當(dāng)前頁面url。
二、返回并刷新前一個頁面
window.open(document.referrer,"_parent",''); //已親測,返回前一個頁面并刷新
或
location.replace(document.referrer);
注:document.referrer 為前一個頁面的URL。
返回不刷新前一個頁面可以用:
history.go(-1);
或
history.back();
二、定時刷新(或跳轉(zhuǎn))頁面
1、定時刷新當(dāng)前頁面
每隔3秒刷新一次頁面:
<meta http-equiv=“refresh” content=“3”>
2、定時跳轉(zhuǎn)
<meta http-equiv=“refresh” content=“2;url=‘https://www.baidu.com'”>
注:<和meta之間不能有空格。
3、其他方法
(1)延遲執(zhí)行一次
setTimeout(code, milliseconds)
注: 使用 clearTimeout() 來停止 setTimeout() 的執(zhí)行。
(2)定時執(zhí)行
setInterval(code, milliseconds);
注: 使用 clearInterval() 來停止 setInterval 的執(zhí)行。
三、刷新包含框架的頁面
1、刷新包含該框架的頁面
<script language=JavaScript>
parent.location.reload();
</script> 2、子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script> 3、刷新另一個框架的頁面
window.parent.frames[1].location.reload(); window.parent.frames.bottom.location.reload(); window.parent.frames[“bottom”].location.reload(); window.parent.frames.item(1).location.reload(); window.parent.frames.item(‘bottom').location.reload(); window.parent.bottom.location.reload(); window.parent[‘bottom'].location.reload();
總結(jié)
到此這篇關(guān)于JS頁面刷新與重新加載功能實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)JS頁面刷新與重新加載內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript中創(chuàng)建原子的方法總結(jié)
這篇文章主要給大家總結(jié)介紹了關(guān)于JavaScript中創(chuàng)建原子的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
javascript實(shí)現(xiàn)在下拉列表中顯示多級樹形菜單的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)在下拉列表中顯示多級樹形菜單的方法,涉及javascript屬性菜單的定義、構(gòu)造及遍歷等技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
js實(shí)現(xiàn)Element中input組件的部分功能并封裝成組件(實(shí)例代碼)
這篇文章主要介紹了純生js實(shí)現(xiàn)Element中input組件的部分功能(慢慢完善)并封裝成組件,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
js報$ is not a function 的問題的解決方法
在html中的程序,跑的好好的,換成jsp在項(xiàng)目中跑,就一直報$ is not a function錯,針對此問題,下面有個不錯的解決方法,大家可以嘗試操作下2014-01-01

