?
Solved

Implenting "idle" chat status

Posted on 2011-02-22
7
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

801 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