Javascript – Detect Inactivity in Browser Tab
You can detect when a user stops interacting with the page using pure Javascript. Example below is a scrupt that will reload the page when user becomes inactive for 5 seconds. It will still run even though you are in another tab.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <script> onInactive(5, function () { window.location.reload(); }); function onInactive(seconds, cb) { var ms = seconds * 1000; var wait = setTimeout(cb, ms); $(window).bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick', function(){ clearTimeout(wait); wait = setTimeout(cb, ms); }); } </script> |
Do you need help with a project? or have a new project in mind that you need help with?
Contact Me