Skip to main content

Posts

Showing posts with the label JavaScript

How to detect inactivity on web browser

This is something useful for apps which after a period of inactivity time you need to autosave things, clear localStorage, redirect to a logout URL and many other background things, so it does not matter if you are using VueJS or ReactJS you can add this code <!-- Script --> < script type= 'text/javascript' >   var inactivityTime = function () {     var time;     window .onload = resetTimer;     // DOM Events     document .onload = resetTimer;     document .onmousemove = resetTimer;     document .onmousedown = resetTimer; // touchscreen presses     document .ontouchstart = resetTimer;     document .onclick = resetTimer;     // touchpad clicks     document .onscroll = resetTimer;    // scrolling with arrow keys     document .onkeypress = resetTimer;     window .addEventListener( 'scroll' , resetTimer, true );     let coun...