Tutorial: Auto-Refresh after X amount of inactivity Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

    Tutorial: Auto-Refresh after X amount of inactivity

    avatar
    Guest
    Guest


    Solved Tutorial: Auto-Refresh after X amount of inactivity

    Post by Guest Thu Oct 02, 2014 9: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 Thu Oct 02, 2014 5:54 pm; edited 1 time in total
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

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

    Post by Ange Tuteur Thu Oct 02, 2014 12: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.
    avatar
    Guest
    Guest


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

    Post by Guest Thu Oct 02, 2014 5:51 pm

    It's a tutorial. PM sent.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

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

    Post by Ange Tuteur Thu Oct 02, 2014 5:59 pm

    Thanks Wink

    Sent to garbage