How can I track the browser idle time? I am using IE8.
I am not using any session management and don’t want to handle it on server side.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is pure JavaScript way to track the idle time and when it reach certain limit do some action:
This code will wait 60 seconds before showing alert and redirecting, and any action will “reset” the count – mouse click, mouse move or key press.
It should be as cross browser as possible, and straight forward. It also support showing the remaining time, if you add element to your page with ID of
SecondsUntilExpire.The above code should work fine, however has several downsides, e.g. it does not allow any other events to run and does not support multiply tabs. Refactored code that include both of these is following: (no need to change HTML)
The refactored code above is using local storage to keep track of when the counter was last reset, and also reset it on each new tab that is opened which contains the code, then the counter will be the same for all tabs, and resetting in one will result in reset of all tabs. Since Stack Snippets do not allow local storage, it’s pointless to host it there so I’ve made a fiddle:
http://jsfiddle.net/yahavbr/gpvqa0fj/3/