How to refresh page if there is no user activity for few seconds using javascript
html, javascript, jquery
Solution
Here a basic example
(function(seconds) {
var refresh,
intvrefresh = function() {
clearInterval(refresh);
refresh = setTimeout(function() {
location.href = location.href;
}, seconds * 1000);
};
$(document).on('keypress click', function() { intvrefresh() });
intvrefresh();
}(15)); // define here seconds
This will refresh the page every 15 seconds without a keypress or a click event (but if you have same events defined elsewhere making a `stopPropagation()` this won't properly work because the event won't be able to reach the element)
Problem
Possible Duplicate: How To Alter This Code So That It Only Redirects If There Is No Mouse Movement I want to refresh a web page if there is no activity by the user using Javascript. User activity as in Key Press or mouse click.