如何使用JavaScript刷新页面?


当前回答

这适用于所有浏览器:

location.reload();

其他回答

use

location.reload();

or

window.location.reload();

window.location.reload()将从服务器重新加载,并将再次加载所有数据、脚本、图像等。

因此,如果您只想刷新HTML,window.location=document.URL将返回得更快,流量更少。但如果URL中有散列(#),则不会重新加载页面。

问题应该是,

如何使用JavaScript刷新页面

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

你被宠坏了。

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

window.location.reload();

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

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

window.location.reload(true);

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

location.reload();
<i id="refresh" class="fa fa-refresh" aria-hidden="true"></i>

<script>
$(document).on('click','#refresh',function(){
   location.reload(true);
});
</script>