Created
November 27, 2017 04:22
-
-
Save webdevid/3929a15336691b901d351c7caadcd301 to your computer and use it in GitHub Desktop.
refresh page if no activity after 1 minute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* If you want to refresh the page if there is no activity then you need to figure out how to define activity. | |
| Let's say we refresh the page every minute unless someone presses a key or moves the mouse. | |
| This uses jQuery for event binding: */ | |
| var time = new Date().getTime(); | |
| $(document.body).bind("mousemove keypress", function(e) { | |
| time = new Date().getTime(); | |
| }); | |
| function refresh() { | |
| if(new Date().getTime() - time >= 60000) | |
| window.location.reload(true); | |
| else | |
| setTimeout(refresh, 10000); | |
| } | |
| setTimeout(refresh, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment