HTML & Javascript Code:
<script type="text/javascript"> <!-- window.location = "http://www.google.com/" //--> </script>
Javascript Time Delay
Implementing a timed delay in javascript is useful for the following situations:
Showing an "Update your bookmark" page when you have to change URLs or page locations
For download sites that wish to have a few second delay before the page loads and when the download starts
To refresh a web page every specified amount of seconds
The code for this timed delay is slightly involved and is beyond the scope of this tutorial. However, we have tested it and it seems to function properly.
HTML & Javascript Code:
<html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "../javascriptredirect.php" } //--> </script> </head> <body onLoad="setTimeout('delayer()', 5000)"> <h2 >Prepare to be redirected!</h2> <p>This page is a time delay redirect, please update your bookmarks to our new location!</p> </body> </html>
View Page:
The most important part of getting the delay to work is being sure to use the javascript function setTimeout. We want the delayer() function be used after 5 seconds or 5000 miliseconds, so we pass the setTimeout() two arguments.
- 'delayer()' - The function we want setTimeout() to execute after the specified delay.
- 5000 - the number of milisecods we want setTimeout() to wait before executing our function. 1000 miliseconds = 1 second.
Web Page Redirection
Do use javascript for redirections when you change your website's URL or move a file to a new location. Don't use redirections when they could easily be replaced with a normal HTML hyperlink.