禁止浏览器缓存策略
2020-09-05 本文已影响0人
huanghaodong
<html manifest="IGNORE.manifest">
以上设置需要网页刷新一次才能生效,下面代码可以实现打开强制刷新
if(!window.name){
var str = Math.random().toString(36).substr(2);//随机字符串
var S = getQueryString('S')
window.name = 'isreload';
if (S) {
window.location.href = window.location.href.replace(/^([^&]*)\?([^&]*)&?S=([^&]+)(\S*)$/, function(match,$1,$2,$3){
return match.replace($3, str)
})
}else{
if(window.location.search.indexOf('?') > -1){
window.location.search += 'S=' + str;
}else{
window.location.search = 'S=' + str;
}
}
}else{
window.name = ''
}
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}