Create a timer ( setTimeout ) that refreshes the page, and each time you press a key or press a mouse, simply restart the timer.
See this question for code that does most of what you want.
FWIW, here the answer of F. Calderan is rewritten to:
- eliminate unnecessary short circuits
- separate an action from repeating by serving the action as a callback
-
function setIdle(cb, seconds) { var timer; var interval = seconds * 1000; function refresh() { clearInterval(timer); timer = setTimeout(cb, interval); }; $(document).on('keypress click', refresh); refresh(); } setIdle(function() { location.href = location.href; }, 15);
Alnitak
source share