浏览器失去焦点后重新获得 则刷新

1
2
3
4
5
6
7
8
// 浏览器失去焦点后重新获得 则刷新
document.addEventListener('visibilitychange', handleVisibilityChange);
function handleVisibilityChange() {
if (!document.hidden) {
//刷新页面
window.location.reload()
}
}

改变浏览器宽度则刷新

1
2
3
4
5
6
7
8
//改变浏览器宽度则自动刷新
let onloadPage
window.onresize = function(){
window.clearTimeout(onloadPage)
onloadPage = window.setTimeout(()=>{
window.location.reload()
},2000)
}