Javascript 如何使用 jQuery 模拟 ctrl-F5?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7563010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I simulate ctrl-F5 with jQuery?
提问by new_perl
So the refresh should discard the cache, how to do it with jQuery?
所以刷新应该丢弃缓存,用jQuery怎么做?
回答by gilly3
回答by Greg Hewgill
The ability to modify the browser cache is outside the scope of what jQuery can do.
修改浏览器缓存的能力超出了 jQuery 的能力范围。
回答by GONeale
This won't be possible.
这是不可能的。
Just increment the version number to your javascript reference like this every time you wish to force a fresh download:
每次您希望强制重新下载时,只需将版本号增加到您的 javascript 参考中即可:
<script language="javascript" src="scripts/script.js?ver=2"></script>
Just to clarify, the appended ver
parameter has no intrinsic value on the script src
attribute as Slomojo pointed out. It was merely a way to address the problem of a forced file reload and also keep a neat versioning system.
只是为了澄清,正如 Slomojo 指出的那样,附加ver
参数对脚本src
属性没有内在价值。这只是解决强制文件重新加载问题并保持整洁的版本控制系统的一种方法。
回答by pixelbyaj
You can detect ctrl+F5 using following code
您可以使用以下代码检测 ctrl+F5
$(document).keydown(function(e) {
if (e.keyCode == 116 && e.ctrlKey) {
alert('ctrl + F5');
}
});