visibilitychange:当前的活动状态事件
document.hidden:判断当前页面有没有被隐藏 (是否是激活状态)
兼容性:IE10+,Firefox10+,Chrome14+,Opera12.1+,Safari7.1+
例;:判断当前网页有没有被激活
var bowhidden="hidden" in document?"hidden": "webkithidden" in document?"webkithidden": "mozhidden" in document ?"mozhidden": null;
var vibchage="visibilitychange" || "webkitvisibilitychange" || "mozvisibilitychange";
document.addEventListener(vibchage,function (){
/*ie10+ moz webkit 默认*/
if(!document[bowhidden]) /*false*/
{
console.log("激活");
}
else{
/*true*/
console.log("隐藏");
}
});
文章出处:https://blog.csdn.net/weixin_43675447/article/details/88357439
网友评论