js的comet各个浏览器封装lib

    SimpleComet是一个轻量级的comet的封装类, 能智能的识别浏览器,应用不同的comet技术,在firefox浏览器上使用ajax,在IE、opera浏览器上使用htmlfile,iframe.

<script type="text/javascript"> // This function will be called every time the server pushes a new event. function push(event) { 	// For this example, we simply show the excuse on the page. 	document.getElementById('excuse').innerHTML = event; }   // This function will be called when/if the stream closes. function disconnected() { 	// For this example we'll just show a nice message. 	document.getElementById('excuse').innerHTML = '<img src="img/arrow.png" alt="" title="" />'+ 		' Click to see MORE reasons why this souldn\'t work!'; 	document.getElementById('control').value = 'start'; }   // This function is executed when the button is clicked. function toggle() { 	// First we check if the stream is open. 	if (!comet.active) { 		// Lets start streaming! 		comet.open('excuses.php', push, disconnected); 		document.getElementById('control').value = 'stop'; 	} else { 		// Streaming is active, means the user wants to stop it. 		comet.close(); 	} } </script>

<!--?php   // First we load the SimpleComet PHP class and the list of excuses. require('inc/simplecomet.class.php'); $comet = new SimpleComet(); $excuses = file('inc/excuses.txt');   // This is an infinite loop, which makes the stream endless. while (true) { 	// We fetch an excuse at random. 	$excuse = trim($excuses[rand(0, count($excuses))]); 	// If the excuse is too long, we get another one. 	if (strlen($excuse) --> 60) { continue; } 	// Finally, we push our excuse to the client. 	$comet->push($excuse); 	// 5 seconds delay before the next excuse. 	sleep(5); }   ?>


simplecomet能监听出链接是否已经断了,是不是很智能,只要负责服务端的输出就行. 
下载: http://www.mandor.net/files/simplecomet-1.0.zip

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值