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 = '瞅啥呢,快回来!!'; };

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM