Click here to Skip to main content
Click here to Skip to main content

Gmail Internal Chat Like Message Box

By , 14 Sep 2009
 

Introduction

This article provides you with a multi-functional message box window through which the usability of the web-site or any web application increases.

Background

You all might be familiar with using Gtalk / Gmail chat application. Whenever someone sends a message to you, a small window appears at the bottom-right corner of your browser (in case of Gmail / Orkut) or at the bottom-right corner of your desktop. This message window works seamlessly without requiring any kind of user interaction, but still it interacts with the user.

What I have tried to achieve is to implement a similar kind of multi-functional message box window within the web-browser, thereby avoiding all kinds of unwanted clicks and providing all the useful information to the user at any interval of time.

MessageBox - Click to enlarge image

Features

  • Configurable MessageBox window with AJAX Support
  • Can set maximum number of message boxes to be visible
  • Can define the auto reload time, for single message, for all messages or no reload
  • Can create messages through a single function call
  • Can define auto hide time for each message

With this, you can avoid all alert messages / pop-up messages, and still intimate the user about what is going on in the system.

Using the Code

To start with, you are supposed to carry out the following steps:

  1. Include the following CSS and JS files in your HTML page HEAD section:
    <link href="base.css" type="text/css" rel="stylesheet" />
    <link href="theme.css" type="text/css" rel="stylesheet" />
    <script src="MessageBox.js" type="text/javascript"></script>
  2. In the BODY section, create one container to hold the messagebox window and provide a unique ID to it, as given below:
    <DIV ID="MsgContainer" CLASS="MsgContainer"></DIV>
  3. At the end, you need to create an object for message box window.
    • thisObject: Name of the object you are creating
    • msgContainer: ID of the container that holds the messagebox window
    • maxMessages: Maximum number of messages that can be visible at a time
    • autoHideTime: The global auto-hide time for all the messagebox windows that appear
    <SCRIPT LANGUAGE="JavaScript">
    //MessageBox(thisObject, msgContainer, maxMessages, autoHideTime /*milli seconds*/)
    var messagebox = new MessageBox('messagebox', 'MsgContainer', 2, 10000);
    </SCRIPT>

How to Create MessageBox Window?

The MessageBox class provides you two APIs for creating messagebox window. These APIs can be accessed using the MessageBox object that is created above, in step 3.

  1. messagebox.activateMsgBox
    	(msgHeader, url, minutesBeforeReload, autoHideTime, msgType) 

    Invoke this method if you want to display messagebox using AJAX request. No separate AJAX code is required. Just provide a URL from where data is to be fetched.

    Meaning of the Parameters

    • msgHeader: The header content to be displayed
    • url: The URL from where the data is to be displayed
    • minutesBeforeReload: The reload timing in minutes
    • autoHideTime: The auto-hide time in milliseconds
    • msgType: The type of messagebox to be displayed

    The msgType is classified into 4 categories, which is nothing but change in the background color of the message window. Currently, I have set them to:

    {DEFAULT: -1, INFO: '#FFFF80', ALERT: '#FF7E00', ERROR: '#FF0000'};

    It can be accessed using MessageBox object as:

    messagebox.msgTypes.DEFAULT
    messagebox.msgTypes.INFO
    messagebox.msgTypes.ALERT
    messagebox.msgTypes.ERROR
  2. messagebox.createMsgBox(msgHeader, msgContent, msgIndex, autoHideTime, msgType) 

    Invoke this method if you want to statically display a messagebox window. For example, you want to intimate a user about "form saved successfully" through messagebox window.

    Meaning of the Parameters

    • msgHeader: The header content to be displayed
    • msgContent: The contents of the message box (either Text or HTML)
    • msgIndex: Set this to null
    • autoHideTime: The auto-hide time in milliseconds, if set to null, the default settings will be applied
    • msgType: The type of messagebox to be displayed, as shown above

Conclusion

Hope all of you will find this article very useful.

History

  • 14th September, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Niral Soni
Software Developer (Senior) Tata Consultancy Services Ltd.
United Kingdom United Kingdom
Member
I started my career as Java Developer. But now more inclined towards web designing, JavaScript, HTML and CSS.I have good level of expertise on Java, Oracle and JavaScript. Designing Generic components is my main expertise.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberxxxpandit16 Aug '12 - 1:04 
vogas article
GeneralRe: My vote of 1memberNIRAL SONI20 Aug '12 - 7:59 
My sincere apologies that you didn't like this article.
Thanks & Regards,
Niral Soni

QuestionHow to use in asp.net..!!memberdexters0072 Jan '11 - 21:24 
Thanks for providing this great functionality
But i want this functionality in asp.net can it possible if yes than can u provide code for that.....
 

 
Thanks
Chirag DaxiniThumbs Up | :thumbsup:
AnswerRe: How to use in asp.net..!!memberNIRAL SONI3 Jan '11 - 6:07 
Hi,
As I said earlier in the previous replies, this code is purely a javascript based. So, it can be integrated with any kind of framework.
 
In your case, I am not aware of the asp.net framework. But you can easily linkup this with any normal javascript code you are using in your application.
 
Regards,
Niral Soni
GeneralMy vote of 2memberJ Xie26 Sep '10 - 18:55 
trivial
QuestionHow to make it like in Gmail Chatmemberfor120629 Apr '10 - 19:39 
Hi Niral Soni ,
 
Thanks & congrats for doing a good job.
 
I am having one request.Now i am having my website .
 
How to call this n use ? i am new to all websites javascript n dhtml
 
in that i am having some links now if i click any link it postback in that site n this will vanish.How to make it constant and stay while browsing through the site pages in the website .
 
Regards
For1206

GeneralLooks good!memberSandeep Mewara24 Mar '10 - 5:20 
Thumbs Up | :thumbsup:
QuestionHow do i apply this to my application inside eclipse??membermag_geo82 Nov '09 - 16:25 
How do i apply this into my java web based application inside eclipse??
 
and why the messageBody.js showing so many errors in my eclipse platform?
 
Help pls mr.niral....
AnswerRe: How do i apply this to my application inside eclipse??memberNIRAL SONI4 Nov '09 - 19:25 
Hi,
this code can directly be integrated with any kind of web based application.
What is required is to replace the index.htm file with corresponding web based framework.
In your case, it will be index.jsp or something like that.
 
I have also implemented the same in my eclipse project (Dynamic web project (J2EE based)) and I am not getting any kind of errors.
 
If possible, send me the code at - niralhsoni@rediffmail.com
Regards,
Niral Soni
GeneralOther usememberMember 663560716 Oct '09 - 8:39 
Nice article.
 
Do you have a suggestion on how to implement this on a master page and then access it from content pages? My goal is to call it on an error in the content page, but have it live in the master page.
AnswerRe: Other usememberNIRAL SONI22 Oct '09 - 7:37 
The solution to your problem depends upon how your web page is designed.
 
If you are using <FRAMESET> then it wont be possible to satisfy the requirements.
 

If you are using <IFRAME> then there are chances of satisfying your requirements.
 
So, Please clarify exactly how your web pages are interlinked, which page will act as master page and where the content page will be..
 

Regards,
Niral Soni
GeneralGreat job...membermag_geo815 Oct '09 - 2:13 
Hi, thanks a lot for the code..
It's really gonna help me a lot..
GeneralRe: Great job...memberNIRAL SONI22 Oct '09 - 7:38 
Thanks.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 14 Sep 2009
Article Copyright 2009 by Niral Soni
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid