需求:浏览器标签页切换,监听事件
<script> var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null; var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange'); var onVisibilityChange = function(){ if (!document[hiddenProperty]) { console.log('页面非激活'); }else{ console.log('页面激活') /*document.location.reload();//重新加载当前页面*/ } }; document.addEventListener(visibilityChangeEvent, onVisibilityChange); window.localStorage.setItem("fwbl_prePage","1"); window.localStorage.setItem("money_use","1"); </script>
参考地址:https://blog.csdn.net/cczhumin/article/details/50736825