javascript - 闪烁标题栏

标签 javascript asp.net html

我尝试使用非常基本的 HTML 使标题栏闪烁。我试了一下,但下面的代码似乎不起作用,我也不知道为什么。另外,有没有办法让标题栏闪烁文本,但前提是用户没有查看当前浏览器页面?

我的尝试:

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);
            }
        }

最佳答案

这个的副本 make my browser blink as indicator

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

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

<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 版本差别不大(但未测试)

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);
});

关于javascript - 闪烁标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5249692/

相关文章:

javascript - 发布历史;等待回应

javascript - 使用 css transform 提高动画性能

c# - MVC 6 - 如何要求密码来执行 Controller 操作?

c# - 无法将类型 'string' 隐式转换为 'System.DateTime' ,无法转换特定列的数据类型

html - 如何在不破坏的情况下定位 CSS <div>?

html - 定义 HTML5 网页字符集的最佳方式?

javascript - 是否可以限制 javascript 函数的范围?

javascript - jQuery datepicker 导致页面溢出

c# - 使用更多方法提高C#中Parallel.For的性能

html - 如何更改 HTML 字符串中的字体大小?