Tutorial: Auto-Refresh after X amount of inactivity
Page 1 of 1
Tutorial: Auto-Refresh after X amount of inactivity
There may be times were you want to refresh a page via JavaScript when a user has been inactive for several minutes. The below code will refresh the page in 10 minutes if there is no activity. Time is counted in milliseconds. The reload will time out in 10 seconds if there is a problem. Taking a 0 out of 600000 makes the refresh time one minute.
Source: http://stackoverflow.com/questions/4644027/auto-reload-web-page-if-there-is-no-recent-activity
- Code:
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function(e) {
time = new Date().getTime();
});
function refresh() {
if(new Date().getTime() - time >= 600000)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}
setTimeout(refresh, 10000);
Source: http://stackoverflow.com/questions/4644027/auto-reload-web-page-if-there-is-no-recent-activity
Last edited by adukes_007 on October 2nd 2014, 6:54 pm; edited 1 time in total
Guest- Guest
Re: Tutorial: Auto-Refresh after X amount of inactivity
Hello,
Is this a support question, or a tutorial ? If it's a tutorial, please check the link in my signature named Submit a tutorial.
Is this a support question, or a tutorial ? If it's a tutorial, please check the link in my signature named Submit a tutorial.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum