0

I am working on a browser-based instant messaging client, and this application needs to know when the user is idle, if possible. Is there a way, in any major browser, for the application to detect the user's idle time system-wide? Failing that, are there any recommended techniques for detecting when the user was last active in the application itself, and possibly in other pages under the same domain?

1
  • Look into the javascript event handlers for keyboard and mouse activity: javascriptkit.com/jsref/eventkeyboardmouse.shtml The user would be idle if they are not invoking one these events after a set period of time. Commented Jun 25, 2011 at 21:23

1 Answer 1

1

If user goes to different page, we can assume he's not idle, so the problem gets reduced to 'is user active on current page?'

You can set timeout in onMouseMove event of body. When timeout fires, you know user's been inactive for some period of time. If it doesn't, and you receive a onMouseMove before timeout, you simply clear the timeout. You can also deal with onKeyPress in the same way.

This could be a little harder if user would open many tabs of your page, but I would just use localStorage for some way of communication between those tabs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.