日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

js的comet各个浏览器封装lib

發(fā)布時間:2024/10/8 HTML 106 豆豆
生活随笔 收集整理的這篇文章主要介紹了 js的comet各个浏览器封装lib 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

? ? SimpleComet是一個輕量級的comet的封裝類, 能智能的識別瀏覽器,應(yīng)用不同的comet技術(shù),在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能監(jiān)聽出鏈接是否已經(jīng)斷了,是不是很智能,只要負責服務(wù)端的輸出就行.?
下載:?http://www.mandor.net/files/simplecomet-1.0.zip

轉(zhuǎn)載于:https://www.cnblogs.com/torome/archive/2011/03/10/1979944.html

總結(jié)

以上是生活随笔為你收集整理的js的comet各个浏览器封装lib的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。