Location Objects has three methods --
assign() Used to load a new document
reload() Used to reloads the current document.
replace() Used to replace the current document with a new one
<button style="display:block; vertical-align:middle; height:2.82em;"
title="Cargar nuevamente el código fuente sin darle un [Enter] a la dirección en la barra de direcciones"
class="ui-state-active ui-corner-all ui-priority-primary"
onclick="javascript:window.location.reload(true);">
<span style="display:inline-block;" class="ui-icon ui-icon-refresh"></span>
[<b>CARGAR NUEVAMENTE</b>]
</button>
window.location.href = window.location.pathname + window.location.search + window.location.hash;
// creates a history entry
JavaScript 1.1
window.location.replace(window.location.pathname + window.location.search + window.location.hash);
// does not create a history entry
JavaScript 1.2
window.location.reload(false);
// If we needed to pull the document from
// the web-server again (such as where the document contents
// change dynamically) we would pass the argument as 'true'.
70
这对我有用:
function refresh() {
setTimeout(function () {
location.reload()
}, 100);
}
17 回答
尝试:
设置为“true”的参数会从服务器重新加载新副本 . 离开它将从缓存服务页面 .
更多信息可以在MSDN和Mozilla documentation找到 .
使用此按钮刷新页面
DEMO
您可以使用
window.location.reload();
执行此任务 . 由于有很多方法可以做到这一点,但我认为这是用JavaScript重新加载同一文档的适当方法 . 这是解释可以使用JavaScript
window.location
对象获取当前页面地址(URL)
将浏览器重定向到另一个页面
重新加载同一页面
window
:在JavaScript中表示浏览器中的打开窗口 .location
:在JavaScript中保存有关当前URL的信息 .location
对象类似于window
对象的片段,并通过window.location
属性调用 .location
对象有三种方法:assign()
:用于加载新文档reload()
:用于重新加载当前文档replace()
:用于替换当前文档的新文档所以这里我们需要使用
reload()
,因为它可以帮助我们重新加载同一个文档 .所以像
window.location.reload();
一样使用它 .Online demo on jsfiddle
要让浏览器直接从服务器检索页面而不是从缓存中检索页面,可以将
true
参数传递给location.reload()
. 此方法与所有主流浏览器兼容,包括IE,Chrome,Firefox,Safari,Opera .有关
location
对象的更多信息,请参见MDC page .这是535 ways to reload the page using JavaScript,最简单的是
location = location
.这是第50个:
这应该工作:
要么
我更喜欢这个,原因如下:
删除#后面的部分,确保页面在不会重新加载包含它的内容的浏览器上重新加载 .
如果您最近提交表单,它不会询问您是否要重新发布最新内容 .
它甚至可以在最新的浏览器上运行 . 在Lasted Firefox和Chrome上测试过 .
或者,您可以使用最新的官方方法执行此任务
使用按钮或只是将其放在“a”(锚)标签内:
尝试这些以满足其他需求:
谢谢,这篇文章非常有用,不仅可以用建议的答案重新加载页面,还可以给我一个将jQuery UI图标放到按钮的想法:
2016 -07-02
你可以简单地使用
其中document.URL获取当前页面URL,window.location重新加载它 .
如果你放
在页面的开头,没有其他条件限定为什么代码运行,页面将加载,然后继续重新加载自己,直到您关闭浏览器 .
To reload a page using JavaScript, use:
20秒后自动重新加载页面 .
我正在寻找有关使用POST请求检索的页面上的重新加载的一些信息,例如在提交
method="post"
表单之后 .要重新加载页面 keeping the POST data, 使用:
window.location.reload();
要重新加载页面 discarding the POST data (perform a GET request), 使用:
window.location.href = window.location.href;
希望这可以帮助其他人寻找相同的信息 .
要简单易用,请使用
location.reload()
. 如果要从服务器中获取内容,也可以使用location.reload(true)
.JavaScript 1.0
JavaScript 1.1
JavaScript 1.2
这对我有用:
http://jsfiddle.net/umerqureshi/znruyzop/