方法一: 此方法無缺陷,但不知為何不能在博客園后台使用(可能是博客園有限制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 = '瞅啥呢,快回來!!'; };