tags:

views:

103

answers:

4

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
+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
+1  A: 

The simplest way is using HTML META tag like this:

<meta http-equiv="refresh" content="3;url=http://example.com/" />

WikiPedia

Ehsan
+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
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