Thursday 4 September 2014

Facebook chat :Simple Shout-Box

Facebook chat :Simple Shout-Box (PHP/jQuery)

In this tutorial I will teach you how to make an Shout-Box like the one on Facebook using PHP and jQuery .The little chat box from Facebook doesn’t take up much space and people cand instantly interact with their friends. Let’s create an Shout Box similar to Facebook chat box .

CSS Code for Facebook chat style

Should work in Chrome, Firefox and ie8+.

 Shout Box HTML

Look at Shout Box markup, you can see username , mesagge fields and the div with “message_box” class, wehere user messages are loaded from the database .

 jQuery

We will refresh chat every second using setInterval() – it sends ajax call to shot.php and loads returned data into the element . So the Shout Box get updated with any newly added message .
When user writes one thing and hit enter key, we want to send entered information to shout.php. The keypress() technique triggers once a button is pressed down, and (evt.which == 13) condition makes positive key pressed is Enter key, then we are able to proceed with Ajax $.post() method, as shown in example below. you’ll replace keypress() with .click() method, however you wish to feature button in your HTML.
And the example below slides up or down Shout Box when a user clicks close or open icon .

 And finally, PHP

Content of PHP file shout.php with some MySQL query:

 So, that’s all folks ! I hope you enjoy it !

fb shoutbox Facebook chat :Simple Shout Box (PHP/jQuery)

No comments:

Post a Comment