javascript - 什么命令相当于 Shift + F5 用于 JS 或 jQuery?
问题描述
我想清除缓存并硬重新加载浏览器,但是当文档准备好时如何使用 JS/jQuery 命令来做到这一点?
我的参考:
我在下面尝试过,但除了评论外没有工作,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");
}
});
推荐阅读
- javascript - Window.print 在 JavaScript 的打印提示中显示平板电脑视图
- r - 有什么方法可以使用并行来加速 plotVenn() 过程?
- php - XML 文件中的更改不会反映在 HTML 页面中
- c# - 当在同一个 ViewCell 中点击编辑器时,为什么我的 Picker 的 Focused+Unfocused 事件会触发?
- javascript - HTML 表单未在 Safari 和 iOS Safari 上提交
- ruby-on-rails - 学习足够的 Rails -- 非管理员用户无法通过 log_in_as 登录
- python - Python 正则表达式匹配任何括在引号括号或括号中的内容
- angular - 以角度显示活动选项卡
- c++ - 在 .cpp 文件之间传递全局字符串变量?
- nestjs - Typeorm 不使用 ormconfig.json 文件