首页 > 其他分享 >通过页面可见性改变事件 visibilitychange修改页面title

通过页面可见性改变事件 visibilitychange修改页面title

时间:2023-10-20 16:04:15浏览次数:32  
标签:document title href visibilitychange images oldTitle titleTime 页面

var titleTime, oldTitle = document.title;

document.addEventListener("visibilitychange", function() {

  if (document.hidden) {

      document.title = "咦,去哪儿啊?";

      clearTimeout(titleTime);

      document.getElementById('shortcut').href = "images/fail.ico";

  }

  else{

      document.title = "欢迎回来!" + oldTitle;

      document.getElementById('shortcut').href = "images/favicon.ico";

      titleTime = setTimeout(function(){

          document.title = oldTitle;

      }, 2e3)

  }

})

标签:document,title,href,visibilitychange,images,oldTitle,titleTime,页面
From: https://blog.51cto.com/u_16307147/7955126

相关文章