How to reload a page after x seconds? client side or server trick?

Hi :slight_smile:

Hopefully the title is quite self explanatory. I’d like to reload a page after x seconds. Is that possible using javascript. I guess yes. Does someone know a place where I could find such a script?

Thanks a lot :slight_smile:


<script language="JavaScript" type="text/javascript">
setTimeout("location.href = 'redirect_here.html'",10000); // milliseconds, so 10 seconds = 10000ms
</script>

Note that this script should be in the redirect_here.html too, if you wish to keep on reloading.
However, you can also do this with pure html. Like this:


<meta http-equiv="refresh" content="10; url=redirect_here.html">

(the first parameter of the content-attribute means the time in seconds)
Put it between the starting/ending head tags.

thanks a lot for your reply :slight_smile:

I really appreciate it.

Is there a way to display the countdopwn on the page?

Somthing like this?


<html>
<head>
<script type="text/javascript">
var timer=0;
function startTimer()
{
	setInterval("timerUp()",1000);
}

function timerUp()
{
	timer++;
        var resetat=180; //change this number to adjust the length of time in seconds
	if(timer==resetat)
	{
		window.location.reload();
	}
	var tleft=resetat-timer;
	document.getElementById('timer').innerHTML=tleft;
}
	
</script>
</head>
<body onload="startTimer()">
Seconds until page reloads:
<div id="timer">
</div>
</body>
</html>

Currently it is set to refresh after 3 minutes, note the 180 seconds

That should be


window[b].[/b]location.reload();

:wink:

That’s what’s there. . . .?? [edit]Ahh, I see, it’s a comma, sry typo. Fixed.[/edit]