欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

序號(hào)方法
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 方法

語(yǔ)法: location.reload([forceGet])

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

2、 replace 方法

語(yǔ)法: location.replace(URL)

說(shuō)明: 該方法通過(guò)指定URL替換當(dāng)前緩存在歷史里(客戶(hù)端)的項(xiàng)目,因此當(dāng)使用replace方法之后,你不能通過(guò)“前進(jìn)”和“后退”來(lái)訪(fǎng)問(wèn)已經(jīng)被替換的URL。 通常使用location.reload() 或者是 history.go(0) 來(lái)刷新當(dāng)前頁(yè)面,此方法類(lèi)似點(diǎn)F5刷新,所以當(dāng)method=”post”時(shí),因?yàn)镾ession的安全保護(hù)機(jī)制,會(huì)出現(xiàn)“網(wǎng)頁(yè)過(guò)期”的提示。

例: location.replace(location.href);
其中l(wèi)ocation.href為當(dāng)前頁(yè)面url。

二、返回并刷新前一個(gè)頁(yè)面

window.open(document.referrer,"_parent",''); //已親測(cè),返回前一個(gè)頁(yè)面并刷新

location.replace(document.referrer);

注:document.referrer 為前一個(gè)頁(yè)面的URL。

返回不刷新前一個(gè)頁(yè)面可以用:

history.go(-1);

history.back();

二、定時(shí)刷新(或跳轉(zhuǎn))頁(yè)面

1、定時(shí)刷新當(dāng)前頁(yè)面

每隔3秒刷新一次頁(yè)面:

<meta http-equiv=“refresh” content=“3”>

2、定時(shí)跳轉(zhuǎn)

<meta http-equiv=“refresh” content=“2;url=‘https://www.baidu.com'”>

注:<和meta之間不能有空格。

3、其他方法

(1)延遲執(zhí)行一次

setTimeout(code, milliseconds)
注: 使用 clearTimeout() 來(lái)停止 setTimeout() 的執(zhí)行。

(2)定時(shí)執(zhí)行

setInterval(code, milliseconds);
注: 使用 clearInterval() 來(lái)停止 setInterval 的執(zhí)行。

三、刷新包含框架的頁(yè)面

1、刷新包含該框架的頁(yè)面

<script language=JavaScript>
    parent.location.reload();
</script> 

2、子窗口刷新父窗口

<script language=JavaScript>
    self.opener.location.reload();
</script> 

3、刷新另一個(gè)框架的頁(yè)面

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頁(yè)面刷新與重新加載功能實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)JS頁(yè)面刷新與重新加載內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論