如果当前页面处于活动状态,我需要确定。 我知道我可以找到标签获得/失去焦点的答案:
https://stackoverflow.com/a/1760268/449553
没关系,如果标签状态改变,但我需要获得初始值。 有几种方法可以打开页面:
据我所知,该页面需要一些时间来加载。所以我需要在DOM加载后获取此值。 有没有办法找到这个价值?
答案 0 :(得分:0)
var visibilityChange,hidden, state;
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";
}
document.addEventListener(visibilityChange, function() {
document.title = document[state];
}, false);
document.title = document[state];
if(document[state]==="hidden"){
//hidden
}else{
//show
}