Build With Anant

Build With Anant

Share this post

Build With Anant
Build With Anant
Gmail/Facebook Style jQuery Chat
User's avatar
Discover more from Build With Anant
Demystifying AI-powered software building, one app at a time
Already have an account? Sign in

Gmail/Facebook Style jQuery Chat

Anant Garg's avatar
Anant Garg
May 13, 2009

Share this post

Build With Anant
Build With Anant
Gmail/Facebook Style jQuery Chat
Share

Introduction
Everyone loves the gmail and facebook inline chat modules. This jQuery chat module enables you to seamlessly integrate Gmail/Facebook style chat into your existing website.

jQuery Chat

Features
1. Gmail style bottom right display of chat boxes
2. Keeps chat boxes open and stores state (data) even when pages are browsed/refreshed similar to Facebook
3. Displays “Sent at…” after 3 minutes of inactivity
4. Displays “X says…” & blinks chat boxes when window is not in focus
5. Minimize and close chat boxes
6. Auto-resize of text input box
7. Auto-scrolling of chat text
8. Auto-back-off polling policy (hits the server less-often when chat activity is low)
9. Extremely simple to integrate into existing site

Demo
Please load the following links in different browsers otherwise it wont work:
(Note that due to users trying out the chat links below at the same time, it might work slightly erratically because the username is actually not supposed to be used by multiple users at the same time)

Sample Chat User One
Sample Chat User Two
Sample Chat User Three

Getting Started
First download the module (link below)

The script does not manage rosters (i.e. which users are online etc.), it only enables users to chat with each other. I assume your current application already provides that functionality. You must also make sure that $_SESSION[‘username’] is being set when your website session begins. You will understand the logic better after you try the sample files that I have provided.

You must first create a mySQL table as below (or import db.txt)

CREATE TABLE `chat` (
  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `from` VARCHAR(255) NOT NULL DEFAULT '',
  `to` VARCHAR(255) NOT NULL DEFAULT '',
  `message` TEXT NOT NULL,
  `sent` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  `recd` INTEGER UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
 INDEX `to` (`to`),
 INDEX `from` (`from`)
)
ENGINE = InnoDB;

Add the following scripts to your page template

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/chat.js"></script>

Add the following CSS to your page template

<link type="text/css" rel="stylesheet" media="all" href="css/chat.css" />
<link type="text/css" rel="stylesheet" media="all" href="css/screen.css" />

<!--[if lte IE 7]>
<link type="text/css" rel="stylesheet" media="all" href="css/screen_ie.css" />
<![endif]-->

Now in your list of users online, add “javascript:chatWith(‘USERNAME’);” function where USERNAME is the username for that particular user who he/she wants to chat with.

Once that is done, edit chat.php and set your database parameters and try your website.

For better understanding, load 3 different browsers (internet explorer, firefox, safari) and point them to samplea.php, sampleb.php and samplec.php.

Click on “chat with john doe” link and watch the chat functionality come alive!

Inorder to integrate your existing website, you must place all your content between the “main_container” div tag.

Browser Compatibility
1. Firefox 2+
2. Internet Explorer 6+
3. Safari 2+
4. Opera 9+

Licensing
This chat script can be used for free under GPL-style license for non-commercial purposes. For commercial purposes, please purchase a license.

Download

jQuery Chat Module. If you would like a more full featured inline chat software, have a look at CometChat.

Future Updates
1. Gmail style pop-out functionality
2. Gmail style emoticons
3. Gmail style video chat
4. Comet integration
5. Jabber integration

Comments/Suggestions?
Do let me know your suggestions on how we can improve this code or any other features you would like to add.

Spread The Word
If you like what you are reading, then please help spread the word by re-tweeting, blogging and dzone upvoting or use the ShareThis button below. Thank you.


Subscribe to Build With Anant

By Anant Garg · Launched 6 months ago
Demystifying AI-powered software building, one app at a time

Share this post

Build With Anant
Build With Anant
Gmail/Facebook Style jQuery Chat
Share

Discussion about this post

User's avatar
Cross-domain cookies/sessions in Safari and all other browsers
Want to read a simplified version of this article?
Feb 18, 2010 • 
Anant Garg

Share this post

Build With Anant
Build With Anant
Cross-domain cookies/sessions in Safari and all other browsers
Write your own PHP MVC Framework (Part 1)
What is MVC?
Mar 13, 2009 • 
Anant Garg

Share this post

Build With Anant
Build With Anant
Write your own PHP MVC Framework (Part 1)
Build a PHP SaaS app from scratch
This is the first of 3 posts which will talk about launching your own SaaS product (or converting your existing single tenant app to a SaaS app).
Jun 10, 2013 • 
Anant Garg

Share this post

Build With Anant
Build With Anant
Build a PHP SaaS app from scratch

Ready for more?

© 2025 Anant Garg
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Create your profile

User's avatar

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.