对于JS或jQuery,什么命令与Shift+F5等效



我想清除缓存并硬重新加载浏览器,但当文档准备好时,如何使用JS/jQuery命令?

我的参考:

  1. 第一个链接
  2. 第二个链接
  3. 第三链路

我在下面尝试过,但除了用this one评论外,没有工作,但它不断地重新加载,永不停止。为什么会发生这种情况?如何使其仅重新加载1次。

$(document).ready(function(){
// window.location.reload(false);
// document.location.reload(true);
// window.location.reload(true);
// window.location.href = window.location.href;
// location.reload(true); //this one
});

更新:在谷歌上搜索并尝试了这个,但不起作用。

sessionStorage.setItem("origin", window.location.href);
$(document).ready(function(){
if(window.location.href == sessionStorage.getItem("origin")){
window.location.reload();
sessionStorage.removeItem('origin');
}
});

您可以为此设置localStorage,只需检查localStorage是否有值即可。如果没有,请先重新加载,然后设置一个值。看看下面的例子:

$(document).ready(function () {
var reload = localStorage.getItem('reload');
console.log(reload);
if (reload === null) {
location.reload(true);
localStorage.setItem('reload', "stop");
}
});

最新更新