多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
方法1: 简单有效,将整个窗口绑定onblur和onfocus。 ``` window.onblur = function() { document.title = "(●—●)"; }; window.onfocus = function() { document.title = "啦啦啦啦"; } ``` 方法2: 参考链接:http://www.webhek.com/post/page-visibility.html ``` // 各种浏览器兼容 var hidden, state, visibilityChange; if (typeof document.hidden !== "undefined") { hidden = "hidden"; visibilityChange = "visibilitychange"; state = "visibilityState"; } else if (typeof document.mozHidden !== "undefined") { hidden = "mozHidden"; visibilityChange = "mozvisibilitychange"; state = "mozVisibilityState"; } else if (typeof document.msHidden !== "undefined") { hidden = "msHidden"; visibilityChange = "msvisibilitychange"; state = "msVisibilityState"; } else if (typeof document.webkitHidden !== "undefined") { hidden = "webkitHidden"; visibilityChange = "webkitvisibilitychange"; state = "webkitVisibilityState"; } // 添加监听器,在title里显示状态变化 document.addEventListener(visibilityChange, function() { document.title = document[state]; }, false); // 初始化 document.title = document[state]; ```