浏览器标题栏闪动

2013-8-13 liyangweb.com 李杨 JavaScript

当网页有新消息时,如何能引起用户的注意呢?

我们可以在浏览器的标题栏中来闪动提醒,这样即使当前页面在后台,用户也可以很只管的看到提示消息。

代码如下:

<meta charset="utf-8" />
<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('www.liyangweb.com');
//-->
</script>

<a onclick="blink.stop()">点此停止</a>

 

标签: JavaScript

评论:

www
2013-08-13 20:36
靠有广告了;牛逼
liyangweb.com 李杨
2013-08-13 20:45
@www:(*^__^*)域名钱不知道猴年马月才能赚回来~~~

发表评论:

Powered by emlog 冀ICP备13011830号-1