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 2/10/2014, 23:54; edited 1 time in total