亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JS頁面刷新與重新加載功能實現(xiàn)(關(guān)閉當(dāng)前窗口)

 更新時間:2023年10月14日 09:28:28   作者:HaleyTiger  
在計算機網(wǎng)頁中如果我們想獲取當(dāng)前頁面最新的內(nèi)容,可以刷新當(dāng)前頁面重新獲取數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于JS頁面刷新與重新加載功能實現(xiàn)(關(guān)閉當(dāng)前窗口)的相關(guān)資料,需要的朋友可以參考下

一、刷新或重新加載當(dāng)前頁面

序號方法
1history.go(0)
2location.reload()
3location=location
4location.assign(location)
5document.execCommand(‘Refresh’)
6window.navigate(location)
7location.replace(location)
8document.URL=location.href

1、reload 方法

語法: location.reload([forceGet])

參數(shù): forceGet, 可選參數(shù), 默認(rèn)為 false,從客戶端緩存里取當(dāng)前頁。true, 則以 GET 方式,從服務(wù)端取最新的頁面, 相當(dāng)于客戶端點擊 F5(“刷新”)

2、 replace 方法

語法: location.replace(URL)

說明: 該方法通過指定URL替換當(dāng)前緩存在歷史里(客戶端)的項目,因此當(dāng)使用replace方法之后,你不能通過“前進(jìn)”和“后退”來訪問已經(jīng)被替換的URL。 通常使用location.reload() 或者是 history.go(0) 來刷新當(dāng)前頁面,此方法類似點F5刷新,所以當(dāng)method=”post”時,因為Session的安全保護(hù)機制,會出現(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頁面刷新與重新加載功能實現(xiàn)的文章就介紹到這了,更多相關(guān)JS頁面刷新與重新加載內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論