Created
February 15, 2017 13:15
-
-
Save danbrianwhite/2b5440499c46eedfe7eebe40e3b897a7 to your computer and use it in GitHub Desktop.
Refresh every x seconds on the exact modulus second
This file contains 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
function refreshEvery(secs) { | |
secs = typeof secs === 'undefined' && secs < 1 ? 1 : secs; | |
var now = new Date(); | |
var hours = now.getHours(); | |
var minutes = now.getMinutes(); | |
var seconds = now.getSeconds(); | |
seconds = seconds + (secs - (seconds % secs)) | |
var then = new Date(); | |
then.setHours(hours); | |
then.setMinutes(minutes); | |
then.setSeconds(seconds); | |
then.setMilliseconds(0); | |
var timeout = (then.getTime() - now.getTime()); | |
setTimeout(function() { window.location.reload(true); }, timeout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment