|
|
Automatic Redirection
You are here: irt.org | Articles | JavaScript | Location | Automatic Redirection Published on: Sunday 8th June 1997 By: Martin Webb IntroductionAs people move their web pages from one ISP to another, or they invest in their own vanity URL, the older pages are still visited until people become aware of the new location. This article describes how to create a page to place on at your old address that will automatically redirect the visitor to the new page. There are two methods we can use, one JavaScript and one non JavaScript using the META tag. There are browsers that do not support one or even both of these methods, therefore we will include an option for the user to manually move forward to the new location. It seems a good idea to pause before the moving on to the new location, as this enables us to inform the visitor that the location has changed and request them to update any bookmarks they may have set. If we don't do this then they may revisit via the old location forever, or until the old pages are eventually removed and the redirection lost. Meta RefreshThe META tag we will use is:
Which should be placed between the <HEAD> and </HEAD> HTML tags. Currently the above example will not do anything as the content property is missing. The content property has two values, the amount of time in seconds before refreshing, and an optional value specifying a URL to refresh the current page with. The following example will load the new page after 10 seconds:
JavaScript RedirectThe other method is to use JavaScript to change the current pages location after 10 seconds using the setTimeout and onLoad method. The onLoad method is placed within the HTML <BODY> tag. The following example will invoke the redirect() function once the current page has totally loaded:
Within the redirect() function we can use the setTimeout method to invoke another function after a delay. The following example invokes the go_now() function after 10 seconds:
Now all we need is the go_now() function which changes the current location:
The combined solutionNow we can combine all of the above to create an automatic redirect page:
Why not try this example, which redirects you back to this page after 10 seconds. Feedback on 'Automatic Redirection'
View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|