function getCookie(name) {
var strCookie = document.cookie;
var arrCookie = strCookie.split("; ");
for (var i = 0; i < arrCookie.length; i++) {
var arr = arrCookie[i].split("=");
if (arr[0] == name) return arr[1];
}
return "";
}
var checkkey = getCookie("cookieName");
var userAgent = navigator.userAgent;
var isIE = userAgent.indexOf('Trident') > -1;
if (isIE) {
$(window).focus(function () {
debugger;
if (checkkey != getCookie("cookieName")) {
$.messager.alert({
title: "提示",
msg: "检测到登录账号有变化刷新浏览器",
icon: "icon",
onClose: function () {
window.location.reload();
}
});
}
})
}
else {
var bowhidden = "hidden" in document ? "hidden" : "webkithidden" in document ? "webkithidden" : "mozhidden" in document ? "mozhidden" : null;
var vibchage = "visibilitychange" || "webkitvisibilitychange" || "mozvisibilitychange";
document.addEventListener(vibchage, function () {
if (!document[bowhidden]) /*false*/ {
if (checkkey != getCookie("cookieName")) {
$.messager.alert({
title: "提示",
msg: "检测到登",
icon: "icon",
onClose: function () {
window.location.reload();
}
});
}
}
});
}
来源:oschina
链接:https://my.oschina.net/weibangbang/blog/3209085