Gurminder Gurminder - 9 months ago 36
HTML Question

need javascript to automatically reload page when minute updates

I am using the following code in my website which displays the current time

function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('time').innerHTML =
h + ":" + m;
var t = setTimeout(startTime, 500);
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;

i am also using the automatic refresher tag in my html which reloads page after every 60 seconds

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

what i want is whenever the time changes to next minute the page reloads
which means if current time is 14:05 and when it hits 14:06 the page reloads by reading this time change and NOT by 60 seconds interval from which the user opens the page.


You can set timeout looking at the clock, just get the actual seconds and wait til 60 to reload:

var date = new Date();
},(60 - date.getSeconds())*1000)

Just put that at the head inside a script tag