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.
The forum of the forums

    Tutorial: Auto-Refresh after X amount of inactivity

    avatar
    Guest
    Guest


    Solved Tutorial: Auto-Refresh after X amount of inactivity

    Post by Guest 2/10/2014, 15:09

    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 2/10/2014, 23:54; 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 2/10/2014, 18:54

    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 2/10/2014, 23:51

    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 2/10/2014, 23:59

    Thanks Wink

    Sent to garbage

      Current date/time is 23/9/2024, 04:35