Search code examples
htmlrefresh

Auto Refresh at the top of every hour


This is what I've already tried:

<meta name="Refresh" content="3600">

What would be the best way to go about making a HTML page automatically refresh at 12am PT every day? Or if that's not possible, the top of every hour like 1am, 2am, 3am and so on. Not an hour from when the user loads the page but the top of the next hour.

Everything I've tried so far seems to just refresh every hour from when the page was loaded.


Solution

  • You can't do this with HTML alone. You need Javascript, but it's very easy. Just add this to your HTML:

    <script>
        var current = new Date();
        var future = new Date();
        future.setTime(future.getTime() + 3600000); //3600000 = 1 hour
        future.setMinutes(0);
        future.setSeconds(0);
    
        var timeout = (future.getTime() - current.getTime());
        setTimeout(function() { window.location.reload(true); }, timeout);
    </script>