解决浏览器回退不刷新页面问题

1. window.addEventListener('pageshow', (e) => {   console.log("打印e:", e, e.persisted);   console.log(navigator.userAgent);   if (e.persisted) {     console.log("刷新页面");     location.reload();   } }); 2. // 兼容浏览器(如vivo浏览器等)的页面隐藏 let hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;

 

let visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange'); let onVisibilityChange = function () { if (!document[hiddenProperty]) {   location.reload();   } else {     console.log('页面非激活');   } } document.addEventListener(visibilityChangeEvent, onVisibilityChange);
上一篇:display:none和visibility:hidden的区别


下一篇:display:none与visibility: hidden的区别