The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Tutorial: Auto-Refresh after X amount of inactivity

View previous topic View next topic Go down

Solved Tutorial: Auto-Refresh after X amount of inactivity

Post by adukes_007 on October 2nd 2014, 10:09 am

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.

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

adukes_007
Forumember

Male Posts : 229
Reputation : 1
Language : English
Location : Alabama- Forrest Gump Land

http://www.turbohkforums.com

Back to top Go down

Solved Re: Tutorial: Auto-Refresh after X amount of inactivity

Post by Ange Tuteur on October 2nd 2014, 1:54 pm

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.

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2684
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Tutorial: Auto-Refresh after X amount of inactivity

Post by adukes_007 on October 2nd 2014, 6:51 pm

It's a tutorial. PM sent.

adukes_007
Forumember

Male Posts : 229
Reputation : 1
Language : English
Location : Alabama- Forrest Gump Land

http://www.turbohkforums.com

Back to top Go down

Solved Re: Tutorial: Auto-Refresh after X amount of inactivity

Post by Ange Tuteur on October 2nd 2014, 6:59 pm

Thanks Wink

Sent to garbage

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2684
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum