Idle timeout in Javascript


/ Published in: JavaScript
Save to your folder(s)

find idle time in javascript


Copy this code and paste it in your HTML
  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);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.