Chapter 76. Automatically Redirecting the Browser


In Topic 75, you saw how to use a meta tag to set an automatic refresh cycle. The syntax of the meta tag looked like this:

 <meta http-equiv="refresh" content="x,#"> 

FAQ

If I use a refresh meta tag to do a redirect, doesn't the redirect behavior happen again and again?

Not necessarily. After the browser jumps to the new page, the previous page's meta tag no longer applies. If the new page doesn't have a redirect on it, the browser stays put. Of course, if the new page does have a redirect on it, then the browser waits the required number of seconds and jumps again.


where x represents the number of seconds before the browser refreshes the page, and # is browser shorthand for the current document.

Just as you're free to change the value of x, you're free to change the Web page that the browser reloads. Simply supply a different URL in place of the number sign.

In effect, this trick creates a page that automatically redirects the browser to a new location after a specified number of seconds. These kinds of pages are handy to have. Say you just redesigned and reorganized your site, and some old nav categories no longer exist in the new, improved version. But visitors to your site might have bookmarks to the old pages. Instead of frustrating your audience when they try to load a nonex istent document, pop a replacement page like the kind in Figure 76.1 to the location of your old, obsolete page. Very classy.

Listing 76.1. View Source for Figure 76.1.

[View full width]

 <html>   <head>     <title>Uh, oh!</title>     <meta http-equiv="refresh" content="5, http://newpage.htm">   </head>   <body>     <h1>Uh, oh!</h1>     <p>The page you're looking for no longer exists. Your browser will automatically jump  to the new page in five seconds. Please update your bookmarks.</p>   </body> </html> 

Figure 76.1. Use a page like this to redirect your visitors to a new location.


The meta tag in the View Source for Figure 76.1 works just like the one at the beginning of this topic. The 5 in the content attribute indicates a five-second pause, and the URL tells the browser where to jump after the five seconds.

FAQ

What kinds of paths can I use for a meta tag's URL?

The URL in the meta tag can be any type of path: absolute, document-relative, or root-relative.


Five seconds is probably way too long a wait for most of your visitors. Still, you want to give the few who actually read your content a fair chance to see what the page says before the browser jumps away, in which case five seconds is probably way too short. How do you satisfy both types of Web surfers?

Easy. Crank up the redirect delay to about ten to fifteen seconds, and include a direct link to the new page, as in Figure 76.2.

Listing 76.2. View Source for Figure 76.2.

[View full width]

 <html>   <head>     <title>Uh, oh!</title>     <meta http-equiv="refresh" content="10, http://newpage.htm">   </head>   <body>     <h1>Uh, oh!</h1>     <p>The page you're looking for no longer exists. Your browser will automatically jump  to the <a href="http://newpage.htm">new page</a> in ten seconds. Please update your  bookmarks.</p>   </body> </html> 

Figure 76.2. To make the redirect go faster for impatient visitors, include a direct link to the correct page.


TIP

Click Here links are never good, yet they seem to crop up in redirect pages a lot. When you include a direct link to the new page, choose the text of the link from the wording of the paragraph, or create a special link that gives the name of the new page.




Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net