2012-10-08

JavaScript 设置浏览器标题闪动

Views: 9585 | 2 Comments

当有新消息或者网页有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>

Related posts:

  1. jQuery延时绑定事件(lazy-bind)
  2. JavaScript+jQuery两栏选择控件
  3. 用Javascript生成弹出窗口
  4. 最简单的JavaScript两级联动示例
  5. JavaScript分页控件
Posted by ideawu at 2012-10-08 11:46:01

2 Responses to "JavaScript 设置浏览器标题闪动"

Leave a Comment