Skip to content

Instantly share code, notes, and snippets.

@webdevid
Created November 27, 2017 04:22
Show Gist options
  • Select an option

  • Save webdevid/3929a15336691b901d351c7caadcd301 to your computer and use it in GitHub Desktop.

Select an option

Save webdevid/3929a15336691b901d351c7caadcd301 to your computer and use it in GitHub Desktop.
refresh page if no activity after 1 minute
/* If you want to refresh the page if there is no activity then you need to figure out how to define activity.
Let's say we refresh the page every minute unless someone presses a key or moves the mouse.
This uses jQuery for event binding: */
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function(e) {
time = new Date().getTime();
});
function refresh() {
if(new Date().getTime() - time >= 60000)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}
setTimeout(refresh, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment