Posted By

hairajeshk on 12/09/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ojuu
Priestd09


Idle timeout in Javascript


 / Published in: JavaScript
 

URL: http://www.andrewsellick.com/67/simple-javascript-idle-state-using-prototype

find idle time in javascript

  1. var idleTime = 5000;
  2. var timeOut = ”;
  3.  
  4. function init() {
  5.  
  6. Event.observe(document.body, ‘mousemove’, resetIdle, true);
  7.  
  8. setIdle();
  9.  
  10. }
  11.  
  12. function onIdleFunction(){
  13.  
  14. alert(‘Your browser has been idle for+ (idleTime/1000) +’ seconds.’);
  15.  
  16. }
  17.  
  18. function resetIdle(){
  19.  
  20. window.clearTimeout( timeOut );
  21. setIdle();
  22.  
  23. }
  24.  
  25. function setIdle(){
  26.  
  27. timeOut = window.setTimeout( "onIdleFunction()", idleTime );
  28.  
  29. }
  30.  
  31. Event.observe(window, ‘load’, init, false);

Report this snippet  

You need to login to post a comment.