-2

I know the syntax for refreshing every xx second

<meta http-equiv="refresh" content="xx">

But I want to refresh page at the time that I setup. For example, I want to refresh at 09:00:00, 09:01:00, 09:02:00, 09:03:00...Refresh at every minute and 00 second, what should I do?? Thank for your help.

Tuan Le
  • 13
  • 7

3 Answers3

-1

Try something like this?

 $(document).ready(function () {
        var timeset = 10;
        setInterval(function() {
            location.reload();
        }, timeset); 
 });

You need document.ready to run once the DOM is ready, see here: https://learn.jquery.com/using-jquery-core/document-ready/

You need to setInterval to repeatedly call a function: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

You need reload to reload the current document: https://www.w3schools.com/jsref/met_loc_reload.asp

This may require some extra tweaking / research into jQuery & other optimisations. Let me know if you have any questions!

NOTE: This uses jQuery, so you will need to include jQuery as a script on your page / in your solution: https://www.w3schools.com/jquery/jquery_get_started.asp

EGC
  • 1,719
  • 1
  • 9
  • 20
  • Not the downvoter, but this reloads the page 10 milliseconds after it loads and includes jQuery needlessly. – AuxTaco Sep 12 '19 at 02:44
  • Obviously the timing needs tuning as per whatever timeframe you required. Please note, as per the second-to-last paragraph to do some of your own research into optimisations if need be :) – EGC Sep 12 '19 at 02:46
-1

Use javascript but if you aware of it just use it on html

<body onload="setInterval(function(){
        alert(); // also change this to location.reload(); to refresh it
    },2000);"> // change 2000ms to 60000ms i put 2s to show but 
    test
</body>
-1

HTML can't do this; you'll either need to set the Refresh header based on the current time or use JavaScript to reload the page. This answer focuses on the JavaScript approach.

You'll need to check the time every second and refresh if it matches your requirements:

<script>
  setInterval(() => {
    if (new Date().getSeconds() === 0) location.reload();
  }, 1000);
</script>

But there's no guarantee this will run every second, and if the :00 second is missed, the page won't reload for at least a minute. A more robust solution saves the current minute (in a closure) and reloads when it changes:

<script>
  setInterval((() => {
    const lastMinute = new Date().getMinutes();
    return () => {
      const newMinute = new Date().getMinutes();
      if (newMinute !== lastMinute) location.reload();
    }
  })(), 1000);
</script>
AuxTaco
  • 4,883
  • 1
  • 12
  • 27