如何使用JavaScript刷新页面?


当前回答

你可以用两种方式写。第一种是重新加载页面的标准方式,也称为简单刷新

location.reload(); //simple refresh

另一种叫做硬刷新。在这里传递布尔表达式并将其设置为true。这将重新加载页面,销毁旧缓存并从头开始显示内容。

location.reload(true);//hard refresh

其他回答

我找到了

window.location.href = "";

or

window.location.href = null;

还进行页面刷新。

这使得移除任何哈希值后重新加载页面变得非常容易。当我在iOS模拟器中使用AngularJS时,这非常好,因此我不必重新运行应用程序。

如果当前页面是通过POST请求加载的,您可能需要使用

window.location = window.location.pathname;

而不是

window.location.reload();

因为如果在POST请求加载的页面上调用window.location.reload()将提示确认。

问题应该是,

如何使用JavaScript刷新页面

window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another

你被宠坏了。

use

location.reload();

or

window.location.reload();

您不需要jQuery中的任何东西,要使用纯JavaScript重新加载页面,只需在location属性上使用reload函数,如下所示:

window.location.reload();

默认情况下,这将使用浏览器缓存(如果存在)重新加载页面。。。

如果您想强制重新加载页面,只需传递一个true值来重新加载方法,如下所示。。。

window.location.reload(true);

此外,如果您已经在窗口范围内,您可以删除窗口并执行以下操作:

location.reload();