欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

JavaScript 设置浏览器标题闪动

程序员文章站 2022-04-12 16:01:58
...
当有新消息或者网页有Ajax内容变动时, 可以闪动浏览器标题(或者Tab标题), 提示用户.

<script type="text/javascript">
<!--
function BlinkTitle(title, timeout){
var self = this;
var timer = null;
var backup = document.title;

self.start = function(title, timeout){
self.stop();

if(title != undefined){
self.title = title;
}
self.timeout = timeout == undefined? 600: timeout;

function blink(){
document.title = document.title == backup? self.title : backup;
}
blink();
timer = setInterval(blink, self.timeout);
}

self.stop = function(){
if(timer != null){
document.title = backup;
clearInterval(timer);
timer = null;
}
}

self.start(title, timeout);
}

var blink = new BlinkTitle('12345');
//-->
</script>

<a onclick="blink.stop()">stop</a>

相关标签: JavaScript