Created
          November 21, 2015 21:47 
        
      - 
      
- 
        Save bran921007/da54425cb00c20cdb3ea to your computer and use it in GitHub Desktop. 
    Detectar si el usuario esta activo o inactivo - Idle javascript
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <script> | |
| var timeoutID; | |
| function setup() { | |
| this.addEventListener("mousemove", resetTimer, false); | |
| this.addEventListener("mousedown", resetTimer, false); | |
| this.addEventListener("keypress", resetTimer, false); | |
| this.addEventListener("DOMMouseScroll", resetTimer, false); | |
| this.addEventListener("mousewheel", resetTimer, false); | |
| this.addEventListener("touchmove", resetTimer, false); | |
| this.addEventListener("MSPointerMove", resetTimer, false); | |
| startTimer(); | |
| } | |
| setup(); | |
| function startTimer() { | |
| // wait 2 seconds before calling goInactive | |
| timeoutID = window.setTimeout(goInactive, 1800000); | |
| } | |
| function resetTimer(e) { | |
| window.clearTimeout(timeoutID); | |
| goActive(); | |
| } | |
| function goInactive() { | |
| // do something | |
| // alert("inactivo"); | |
| window.location.reload(); | |
| } | |
| function goActive() { | |
| // do something | |
| startTimer(); | |
| } | |
| </script> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Genio!