<script>
//替换url中的参数值
function changeUrlArg(url, arg, val) {
var pattern = arg + '=([^&]*)';
var replaceText = arg + '=' + val;
return url.match(pattern) ? url.replace(eval('/(' + arg + '=)([^&]*)/gi'), replaceText) : (url.match('[\?]') ? url + '&' + replaceText : url + '?' + replaceText);
}
$(function () {
//适用于IOS
if (isIOS()) {
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload()
}
};
} else {
//适用于安卓
var page_server_time = $("input[name='page_server_time']").val();
if (page_server_time) {
var cookie_server_time = GetCookie('page_server_time');
//缓存时间大于页面服务器时间,说明页面是旧页面,强制刷新(刷新的时候,页面服务器时间会更新为最新时间,所以不会一直刷新)
if (cookie_server_time && parseInt(cookie_server_time) >= parseInt(page_server_time)) {
var html = changeUrlArg(window.location.href, 'v', Math.random() * 100);
window.location.href = html;
} else {
SetCookie('page_server_time', page_server_time);
}
}
}
});
</script>
评论