document.addEventListener('visibilitychange',function(e){
console.log(document.visibilityState);
let state = document.visibilityState
if(state == 'hidden'){
console.log(document.visibilityState,'用户离开了');
}
if(state == 'visible'){
console.log(document.visibilityState,'回来了');
}
})
标签:visibilityState,log,标签,console,state,浏览器,document,监听
From: https://www.cnblogs.com/HatcherBlogs/p/17374831.html