如何使用哈希刷新页面?

时间:2010-04-10 10:35:55

标签: javascript html

我通过编写window.location = window.location;来刷新页面。但是这不适用于像/ page#c22这样的页面。它只会跳到c22。如何刷新页面?

刷新后不需要使用#c22,但我确信有比window.location = window.location更可靠的方法。

4 个答案:

答案 0 :(得分:8)

您可能想尝试:

window.location.reload(true);
  

reload(forceget):从当前网址重新加载文档。 forceget是一个布尔值,当它为true时,会导致页面始终从服务器重新加载。如果是false或未指定,则浏览器可以从其缓存重新加载页面。 (Source

答案 1 :(得分:3)

您可以使用:

window.location.reload();

The spec for this is here, at the W3C

  

此函数强制宿主应用程序重新加载由位置标识的资源。

答案 2 :(得分:3)

尝试:

location.reload(true)

答案 3 :(得分:1)

Page auto reload with parameters”是一个试图保留get参数的人。

可能您想使用location.pathname

相关问题