If a user is not performing any task on a page i.e the page is idle, is there any way to capture the time the page was idle or nothing was done on it. I am using JSP, struts1, JQM, JS in my project.
Asked
Active
Viewed 2,348 times
1
-
What do you mean by "doing something on it"? – Bergi Jul 26 '12 at 06:47
-
A Page is Event Based, some an action triggers an Event. Are you saying that if there are no "Events" you want to log the "time". Or are you talking about no "server-side" postbacks? – Dane Balia Jul 26 '12 at 06:48
-
check this post out http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly – zoranc Jul 26 '12 at 06:48
2 Answers
1
Idle time implementation using:
- YUI
- jQuery
Or use the below script:
<script type="text/javascript"> idleTime = 0; $(document).ready(function () { //Increment the idle time counter every minute. var idleInterval = setInterval("timerIncrement()", 60000); // 1 minute //Zero the idle timer on mouse movement. $(this).mousemove(function (e) { idleTime = 0; }); $(this).keypress(function (e) { idleTime = 0; }); }) function timerIncrement() { idleTime = idleTime + 1; if (idleTime > 19) { // 20 minutes window.location.reload(); } } </script>

Prakash K
- 11,669
- 6
- 51
- 109

sasikals26
- 835
- 2
- 18
- 41
-
2Nice answer. But please quote the source if you copied pasted the answer from another answer on SO. Just a matter of courtesy. http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly – Ashwin Prabhu Jul 26 '12 at 06:57
0
You can use the Triggers onclick, onmousemove and onkeypress of the body-tag to get the current user action. After one of these has triggered you can set a timestamp and query the idle-time via setTimeout() or setIntervall(). You fetch the current timestamp and subtract the timestamp from the last action.

rollstuhlfahrer
- 3,988
- 9
- 25
- 38