Skip to content

Instantly share code, notes, and snippets.

@jaclync
Created July 21, 2017 06:02
Show Gist options
  • Save jaclync/f810b4595ce4f79a4ff1fb03e8db3ca3 to your computer and use it in GitHub Desktop.
Save jaclync/f810b4595ce4f79a4ff1fb03e8db3ca3 to your computer and use it in GitHub Desktop.
Refresh JS
function refreshAt(hours, minutes, seconds) {
var now = new Date();
var then = new Date();
if (now.getHours() > hours ||
(now.getHours() == hours && now.getMinutes() > minutes) ||
now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
then.setDate(now.getDate() + 1);
}
then.setHours(hours);
then.setMinutes(minutes);
then.setSeconds(seconds);
var timeout = (then.getTime() - now.getTime());
setTimeout(function() { window.location.reload(true); }, timeout);
}
// Then you can add a script tag to call the refreshAt() function.
refreshAt(6, 59, 59); // Will refresh the page at 6:59am 59 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment