一瞬儿光
function getPage() {
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";
}
return {
'hidden': hidden,
'visibilityChange': visibilityChange,
'state': state
};
}
var Page= getPage();
document.addEventListener(Page['visibilityChange'], function() {
if(document[Page['state']] == 'hidden') {
//关闭
} else {
//未关闭
}
}, false);