首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪现标题栏

闪现标题栏
EN

Stack Overflow用户
提问于 2011-03-10 01:27:02
回答 2查看 12.5K关注 0票数 2

我试图得到的标题栏闪光,使用非常基本的HTML。我试过了,但是下面的代码似乎不起作用,我也不知道为什么。另外,有没有一种方法可以使标题栏显示为flash文本,但前提是用户没有查看当前浏览器页面?

我的尝试是:

代码语言:javascript
复制
function Flash() {
            window.setTimeout(function() {
            alert(document.title);
                document.title = (document.title == "Company" ? "Company - flash text" : "Company");
            }, 1000);

            this.stop = function() { 
                document.title = "Company";
                clearTimeout(this.timer);
            }
        }
EN

回答 2

Stack Overflow用户

发布于 2011-03-10 01:32:28

make my browser blink as indicator的副本

但既然我现在写了这个脚本:

https://plungjan.name/SO/flashtitle.html

代码语言:javascript
复制
<script>
var timer="";
var isBlurred=false;
window.onblur=function() {
  isBlurred = true;
  timer=window.setInterval(function() {
    document.title = document.title == "Company" ? "Company - flash text" : "Company";
  }, 1000);
}
window.onfocus=function() { 
  isBlurred = false;
  document.title = "Company";
  clearInterval(timer);
}
</script>

jQuery版本并没有太大的不同(但没有经过测试)

代码语言:javascript
复制
var timer="";
var isBlurred=false;
$(window).on("blur",function() {
  isBlurred = true;
  timer=window.setInterval(function() {
    document.title = document.title == "Company" ? "Company - flash text" : "Company";
  }, 1000);
}).on("focus",function() { 
  isBlurred = false;
  document.title = "Company";
  clearInterval(timer);
});
票数 9
EN

Stack Overflow用户

发布于 2015-04-30 21:23:27

当访问者未查看当前浏览器页面(窗口隐藏、模糊)时,您会询问document.title栏是否闪烁(闪烁)。所以我们必须设置两个函数。首先,我们需要检测浏览器窗口当前是否处于活动状态- visibilityChange(actionFunction)。其次,我们需要开始获取闪烁的条形图- comeBackAlerts()。给你--这个解决方案对我来说很好,希望对你也一样。

代码语言:javascript
复制
/* Set event leaving the page to execute actionFunction */

function visibilityChange(actionFunction) {

  window.focus(); /* window.onfocus = infoIn;  */

  var hidden = "hidden";

  /* Standards: */
  if (hidden in document) {
    document.addEventListener("visibilitychange", actionFunction);
  } else if ((hidden = "mozHidden") in document) {
    document.addEventListener("mozvisibilitychange", actionFunction);
  } else if ((hidden = "webkitHidden") in document) {
    document.addEventListener("webkitvisibilitychange", actionFunction);
  } else if ((hidden = "msHidden") in document) {
    document.addEventListener("msvisibilitychange", actionFunction);
  }
  /* IE 9 and lower: */
  else if ("onfocusin" in document) {
    document.onfocusin = document.onfocusout = actionFunction;
  }
  /* All others: */
  else {
    window.onpageshow = window.onpagehide = window.onfocus = window.onblur = actionFunction;
  }
}


/* Function to make browser window blink in task bar */

var comeBackAlerts = (function() {
  var oldTitle = document.getElementsByTagName('h1')[0].innerText; /* document.title; */
  var msg = "Arbir.ru";
  var intervalId;
  var blink = function() {
    intervalId = setInterval(function() {
      /* document.title = document.title == msg ? ' ' : msg; */
      if (document.title == msg) {
        document.title = oldTitle;
      } else {
        document.title = msg;
      }
    }, 1000);
  };
  var clear = function() {
    clearInterval(intervalId);
    document.title = oldTitle;
    window.onmousemove = null;
    window.onmouseout = null;
    intervalId = null;
  };
  return function() {
    if (!intervalId) {
      blink();
      window.onmousemove = clear;
    }
  };
}());

/* Running the functions */

visibilityChange(comeBackAlerts);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5249692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档