Solved

Implenting "idle" chat status

Posted on 2011-02-22
7
248 Views
Last Modified: 2012-05-11
Hello,

I am implementing a chat script like gmail.

I want to display user's chat status as "idle" when they are navigate away from  the tab for a long time.
Does anyone have an idea for implementing it?

Thanks and Regards
0
Comment
Question by:jacobbbc
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 34953295
Are you using AJAX to make your chat app?
0
 

Author Comment

by:jacobbbc
ID: 34958428
Hi

It is an ajax+php application. I have already written an ajax function to update the user status as "idle" in database. But I am not sure about when I need to call this fuction?

Thanks and Regards
0
 
LVL 14

Expert Comment

by:EMB01
ID: 34960761
Well, without seeing your code it would be hard to write something useful, but the "idle status" function would look similar to your "check messages" function.  You would run the function when you run your checkmessages function in your JS file.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:jacobbbc
ID: 34969091
Hello,

Ok Fine.I have one more question..

How can we identify if a person leaves the browser for a long time?

Thanks and regards
0
 
LVL 14

Expert Comment

by:EMB01
ID: 34969663
Do you mean minimizes the window, closes the window, doesn't move the mouse, doesn't enter any data, or some other condition?
0
 

Author Comment

by:jacobbbc
ID: 34985845
Hello,
 
We would like to include the following conditions to recognize the idle status.

1.minimizes the window for a specific period
2.doesn't move the mouse within a time limit
3.doesn't enter any data  within a time limit.

Do you have any suggestions?

We just want to execute some functions while closing the browser. How can we identify browser close event?

Thanks and regards
0
 
LVL 14

Accepted Solution

by:
EMB01 earned 500 total points
ID: 34987344
To check when a window is minimized:

function detectMinMax(){
      if(!isMin&&((window.screenLeft&&window.screenLeft==-32000)||(window.screenX&&window.screenX==-32000))){
            // window has just been minimized!
            isMin = true;
      } else if(isMin&&((window.screenLeft&&window.screenLeft!=-32000)||(window.screenX&&window.screenX!=-32000))){
            // window has just been unminized!
            isMin = false;
      }
}

Ref.  http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21553336.html

To check whether or not the mouse is moved:

function doSomething(e) {
      var posx = 0;
      var posy = 0;
      if (!e) var e = window.event;
      if (e.pageX || e.pageY)       {
            posx = e.pageX;
            posy = e.pageY;
      }
      else if (e.clientX || e.clientY)       {
            posx = e.clientX + document.body.scrollLeft
                  + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop
                  + document.documentElement.scrollTop;
      }
      // posx and posy contain the mouse position relative to the document
      // Do something with this information
      
}

Ref.  http://www.quirksmode.org/js/events_properties.html

To check whether or not a key has been pressed (jQuery, since jQuery will make most, if not all, of these tasks easier):

var timeout; $('input[type=text]').keypress(function() {
     if(timeout) {
         clearTimeout(timeout);         timeout = null;    
     }      
     timeout = setTimeout(myFunction, 5000)
})

Ref.  http://stackoverflow.com/questions/693849/call-a-javascript-function-after-5-sec-of-last-key-press

To do something before the browser is closed (also, using jQuery):

$(window).unload( function () {
     jQuery.get("someurl")
} );

Ref.  http://stackoverflow.com/questions/653976/call-url-before-closing-of-browser-window

I can't really help you with every single item since there are so many, so it's probably best to open up another question if you need help with these individually.  Thanks for understanding, I hope this is what you're looking for.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web forms being filled out by bots 4 49
How can I implement a "Select All" with this configuration...? 6 48
Make Session back to empty 9 30
VBScript on Html 15 47
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question