<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://mat1.gtimg.com/www/js/jquery/jquery-1.11.1.min.js"></script>
<script>
//判断是否是IE浏览器,包括Edge浏览器
function IEVersion9() {
//取得浏览器的userAgent字符串
var userAgent = navigator.userAgent;
//判断是否IE浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if (fIEVersion < 10) {
return true;
}
return false;
} else {
return false;
}
}
(function () {
window.onload = function () {
(function (g, h, $, b) {
var e, i, f = 'onfocusin' in h && 'hasFocus' in h ? 'focusin focusout' : 'focus blur',
d = ['', 'moz', 'ms', 'o', 'webkit'],
c = $.support,
a = $.event;
while ((i = e = d.pop()) != b) {
i = (e ? e + 'H' : 'h') + 'idden';
if (c.pageVisibility = typeof h[i] == 'boolean') {
f = e + 'visibilitychange';
break
}
}
$(/blur$/.test(f) ? g : h).bind(f,
function (m) {
var l = m.type,
j = m.originalEvent,
k = j.toElement;
if (!/^focus./.test(l) || (k == b && j.fromElement == b && j.relatedTarget == b)) {
a.trigger((i && h[i] || /^(?:blur|focusout)$/.test(l) ? 'hide' : 'show') + '.visibility')
}
})
}(this, document, jQuery));
if (IEVersion9()) {
var o = {}
o.$tabFlag = true;
/** 切换页卡 **/
var changeTab = function () {
console.log(333)
$(document).bind({
'show.visibility': function () { // 当前活跃
o.$tabFlag = true;
console.log("欢迎回来");
},
'hide.visibility': function () { // 失去当前状态
o.$tabFlag = false;
console.log('离开了当前页面')
}
});
}
changeTab();
} else {
//ie9或者其他浏览器调用
document.addEventListener('visibilitychange', function () {
if (!document.hidden) {
console.log("欢迎回到首页");
}
})
}
};
})();
</script>
</head>
<body>
</body>
</html>