企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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); } }) ```