多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] > [参考](https://developer.mozilla.org/zh-CN/docs/Web/API/Page_Visibility_API) ## 概述 监听页面从前台切到后台,或从后台切到前台的状态 ## demo ``` var visibilityChange; if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support visibilityChange = "visibilitychange"; } else if (typeof document.msHidden !== "undefined") { visibilityChange = "msvisibilitychange"; } else if (typeof document.webkitHidden !== "undefined") { visibilityChange = "webkitvisibilitychange"; } document.addEventListener(visibilityChange,function (res) { if (document.hidden) { console.log("document.hidden" ,document.hidden); } else { console.log("document.show" ,document.hidden); } }) ```