h5页面刷新——那些事

回退、go(-1)返回上一页刷新

window.addEventListener('pageshow', (event) => {
	 const navigationType = window.performance && window.performance.navigation.type === 2;
	 const isBackForward = window.performance.getEntriesByType("navigation")[0] && window.performance.getEntriesByType("navigation")[0].type === 'back_forward';
	 if(event.persisted || navigationType || isBackForward) {
	 	window.location.reload();  	 
	 }
}, false);

页面显示就刷新

if (document.visibilityState) {
  document.addEventListener('visibilitychange', function() {
    if (document.visibilityState === 'visible') {
       window.location.reload();   
    }
  });
}
window.onpageshow = function() {
	window.location.reload();  
};

你可能感兴趣的:(javascript,前端)