Published on: 2005-08-15 - Views: 4085

Were you wondering "how do they do" to make you wait some seconds and then push you to another page/site?
You just found the answer.
With a simple javascript function you can send your visitors to another page, allowing them some time to read a message on the actual page.

You only have to add the function definition in your <head>tag and then recall the function in your <body> tag.

Let's see it in depth;
this is the code you have to put into your head section:
<script language="JavaScript">
var destination = "http://www.tutorialstream.com";
function goTo()
{
setTimeout( "window.location.href = destination", 10*1000 );
}
</script>
The variable destination has to contain the url where you want your visitors to be sent; 10*1000 means 10 seconds so if you want to make them wait 5 secs you simply have to type there 5*1000.
Now that we have written our function we have to recall it in the body tag in this way:
<body onload="goTo()">
You can use this script to redirect your visitors when you show them an error page.
You can use this combined to the .htaccess custom error page (see the tutorial here) to redirect our users to the home page once they try to reach a page that doesn't exist.