11

JavaScript 设置浏览器标题闪动

 4 years ago
source link: https://blogread.cn/it/article/6574?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

JavaScript 设置浏览器标题闪动

浏览:2886次  出处信息

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

觉得文章有用?立即:

和朋友一起 共学习 共进步!

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK