javascript监听浏览器窗口切换
方法一: 此方法无缺陷,但不知为何不能在博客园后台使用(可能是博客园有限制document事件)
document.addEventListener("visibilitychange", function() { if(document.visibilityState == 'hidden'){ document.title = '瞅啥呢,快回来!!'; } else{ document.title = '这就对了~~'; setTimeout(function(){ document.title = '要走终究留不住,祝安好~~'; }, 1500); } });
方法二:此方法有缺陷,但能在博客园后台使用(比如你有扩展屏,当前浏览器窗口不切换,当鼠标移动到扩展屏时也会触发该窗口blur事件)
window.onfocus = function () {
document.title = '这就对了~~';
setTimeout(function(){
document.title = '要走终究留不住,祝安好~~';
}, 1500);
};
window.onblur = function () {
document.title = '瞅啥呢,快回来!!';
};

浙公网安备 33010602011771号