监测页面是否切换到后台

2020-07-01  本文已影响0人  凡凡的小web
document.addEventListener("visibilitychange",function(){
 
    if(document.visibilityState=="visible"){
    // console.log("欢迎回来");
    location = location
    //do something
    //继续视频播放
    }
    if(document.visibilityState=="hidden"){
    console.log("不要走!")
    //do something else
    //暂停视频播放
    }
})      

参考

https://www.cnblogs.com/wangmaoling/p/8022561.html
https://www.jianshu.com/p/4e5de223b8db
https://blog.csdn.net/weixin_42861240/article/details/94555114
https://blog.csdn.net/gg451516921/article/details/79133029

// window.addEventListener('pageshow', function(event) {
// dispLog("PageShow Event " + event.persisted);
// console.log(event)
// })

上一篇 下一篇

猜你喜欢

热点阅读