首页 > 其他 > 详细

getHiddenProp() 浏览器状态切换改变

时间:2018-09-21 13:07:09      阅读:217      评论:0      收藏:0      [点我收藏+]
<script>
function getHiddenProp() {
var prefixes = [‘webkit‘, ‘moz‘, ‘ms‘, ‘o‘];

// if ‘hidden‘ is natively supported just return it
if (‘hidden‘ in document) return ‘hidden‘;

// otherwise loop over all the known prefixes until we find one
for (var i = 0; i < prefixes.length; i++) {
if ((prefixes[i] + ‘Hidden‘) in document)
return prefixes[i] + ‘Hidden‘;
}

// otherwise it‘s not supported
return null;
}
function getVisibilityState() {
var prefixes = [‘webkit‘, ‘moz‘, ‘ms‘, ‘o‘];
if (‘visibilityState‘ in document) return ‘visibilityState‘;
for (var i = 0; i < prefixes.length; i++) {
if ((prefixes[i] + ‘VisibilityState‘) in document)
return prefixes[i] + ‘VisibilityState‘;
}
// otherwise it‘s not supported
return null;
}

function isHidden() {
var prop = getHiddenProp();
if (!prop) return false;

return document[prop];
}

// use the property name to generate the prefixed event name
var visProp = getHiddenProp();
if (visProp) {
var evtname = visProp.replace(/[H|h]idden/, ‘‘) + ‘visibilitychange‘;
document.addEventListener(evtname, function () {
document.title = document[getVisibilityState()]+"状态";
},false);
}

// Set the initial value
document.title = document[getVisibilityState()]+"状态";
</script>

 

 

getHiddenProp() 浏览器状态切换改变

原文:https://www.cnblogs.com/xieyongbin/p/9685959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!