Solved

Implenting "idle" chat status

Posted on 2011-02-22
7
246 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now