开发者

Thoughts on a Shoutbox anyone?

I'm wanting to create a shoutbox, though I'm wondering if there is another way to go about this rather than using setInterval to query the database for new shouts every number of seconds. Honestly, I don't like having to go about it this way. Seems a bit redundant and repetitive and just plain old wrong. Not to mention the blinking of the shouts as it grabs the data.

So I'm wondering on how the professionals do thi开发者_如何学编程s? I mean, I've seen shoutboxes that work surperb and doesn't seem to be using any setInterval or setTimeout javascript functions to do this.

Can anyone suggest any ideas or an approach to this that doesn't use setInterval or setTimeout??

Thanks :)


Use javascript to update the shoutbox as people write messages without reloading the whole page. Take a look at the code behind this shoutbox as an example. (Download link is on the right.) There are many other examples of shoutbox that use Javascript to seamlessly pull new "shouts" from the database all over the internet. Many of them are highly customizable so you can change the CSS to achieve whatever styling you want.

Here are a couple more examples of such scripts:
http://www.ajaxdaddy.com/demo-jquery-shoutbox.html
http://www.truefusion.org/TFsBOX/ (Code located here: http://code.google.com/p/tfsbox/ )


Maybe you can use COMET?

HTML5 will allow having web sockets with javascript which will make this even better, but I would not use HTML 5 for that yet, until more people move to browsers which support it.


Instead of using timers, put a refresh button, let users manually update the messages, cbox do like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜