如何使用JavaScript或HTML刷新页面?
如何使用JavaScript或HTML刷新页面?
window.location.reload();
在 JavaScript 中使用。
<meta http-equiv="refresh" content="1">
在 HTML 中使用(其中 1
表示 1 秒)。
以下是使用 JavaScript 重新加载页面的 535 种方法,非常酷:
以下是前 20 种:
location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
location = window['location'].href
location = window['location']['href']
location = window.location['href']
location = self['location']
location = self['location'].href
location = self['location']['href']
location = self.location['href']
location.assign(location)
location.replace(location)
window.location.assign(location)
window.location.replace(location)
self.location.assign(location)
并且最后10个:
self['location']['replace'](self.location['href'])
location.reload()
location['reload']()
window.location.reload()
window['location'].reload()
window.location['reload']()
window['location']['reload']()
self.location.reload()
self['location'].reload()
self.location['reload']()
self['location']['reload']()
[]
和.
访问对象属性。 - RozzAwindow.history.go(0)
;) - Taufik Nur Rahmanda只需使用...
location.reload(true/false);
如果为假,则页面将从缓存中重新加载,否则从服务器重新加载。false
。 - Nabi K.A.Z.window.location.reload()
代替。 - TD1window.location.reload()
这应该有效,不过还有很多不同的选项,比如:
window.location.href=window.location.href
您也可以使用
<input type="button" value = "Refresh" onclick="history.go(0)" />
对我来说它很好用。
使用:
window.location.reload();
www.yoursite.com/page/about?getVer=1&__[date]
即使不需要请求,此方法也至少需要一个请求,因为它已经存在于本地浏览器缓存中。但是与完全不使用缓存相比,开销要小得多(以确保页面显示正确的更新内容)。这仅需要每个页面请求的几个字节,而不是每个页面的所有内容。
重要提示:必须在您的服务器上实现版本信息请求,否则它将返回整个页面。
www.yoursite.com/page/about?getVer=1&__[date]
返回版本字符串的示例:
skg2pl-v8kqb
以下是我的库的一部分代码示例(我认为您可能无法使用它,但也许可以给您提供一些实现思路):
o.gCheckDocVersion = function() // Because of the hard caching method, check document for changes with ajax
{
var sUrl = o.getQuerylessUrl(window.location.href),
sDocVer = o.gGetData( sUrl, false );
o.ajaxRequest({ url:sUrl+'?getVer=1&'+o.uniqueId(), cache:0, dataType:'text' },
function(sVer)
{
if( typeof sVer == 'string' && sVer.length )
{
var bReload = (( typeof sDocVer == 'string' ) && sDocVer != sVer );
if( bReload || !sDocVer )
{
o.gSetData( sUrl, sVer );
sDocVer = o.gGetData( sUrl, false );
if( bReload && ( typeof sDocVer != 'string' || sDocVer != sVer ))
{ bReload = false; }
}
if( bReload )
{ // Hard refresh page contents
window.location.reload(true); }
}
}, false, false );
};
试试这个,运行良好。
jQuery("body").load(window.location.href);