What do I have to do to have a function on a website where it says it will redirect you to the site in 3 seconds or so?
+2
A:
<meta http-equiv="refresh" content="3;url=http://www.google.com/" />
Darin Dimitrov
2010-07-20 16:14:02
+8
A:
You're probably looking for the meta
refresh
tag:
<html>
<head>
<meta http-equiv="refresh" content="3;url=http://www.somewhere.com/" />
</head>
<body>
<h1>Redirecting in 3 seconds...</h1>
</body>
</html>
Note that use of meta
refresh
is deprecated and frowned upon these days, but sometimes it's the only viable option (for example, if you're unable to do server-side generation of HTTP redirect headers and/or you need to support non-JavaScript clients etc).
LukeH
2010-07-20 16:14:35
+2
A:
Or is you want greater control via javascript rather than use the meta tag which would allow you to have a visual count down or whatever. Here's the very basic approach using setTimeout()
<html>
<body onload="timer=setTimeout(function(){ window.location='http://stackoverflow.com';}, 3000)">
<p>You will be redirected in 3 seconds</p>
</body>
</html>
mbrevoort
2010-07-20 16:20:04
This would be the way to go if you want the text to dynamically count down to 0 prior to the redirect. Use a 1 second timer, where the timer function updates the HTML text and then start a new 1 second timer, until 3 seconds have elapsed, then do the redirect.
Remy Lebeau - TeamB
2010-07-20 19:41:55