如何使用JavaScript刷新页面?
当前回答
你可以用两种方式写。第一种是重新加载页面的标准方式,也称为简单刷新
location.reload(); //simple refresh
另一种叫做硬刷新。在这里传递布尔表达式并将其设置为true。这将重新加载页面,销毁旧缓存并从头开始显示内容。
location.reload(true);//hard refresh
其他回答
有很多方法可以重新加载当前页面,但使用这些方法,您可以看到页面更新,但不会有很少的缓存值,因此要克服这个问题,或者如果您希望发出硬请求,请使用以下代码。
location.reload(true);
//Here, it will make a hard request or reload the current page and clear the cache as well.
location.reload(false); OR location.reload();
//It can be reload the page with cache
这适用于所有浏览器:
location.reload();
这对我有用。
function reload(){
location.reload(true);
}
您可能需要使用
location.reload()
或可能需要使用
location.reload(forceGet)
forceGet是一个布尔值,也是可选的。
如果您希望强制浏览器从服务器获取页面,以便同时清除缓存,请将此参数设置为true
您可以使用JavaScript location.reload()方法。此方法接受布尔参数。正确或错误。如果参数为真;页面总是从服务器重新加载。如果是假的;这是默认设置,或者使用空参数浏览器从其缓存中重新加载页面。
带真参数
<button type="button" onclick="location.reload(true);">Reload page</button>
带默认/假参数
<button type="button" onclick="location.reload();">Reload page</button>
使用jquery
<button id="Reloadpage">Reload page</button>
<script type="text/javascript">
$('#Reloadpage').click(function() {
location.reload();
});
</script>