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