Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Detect-and-route with JavaScript

By Molly E. Holzschlag
2005-03-31


Routing by browser type

One of the most common uses for these detection scripts is to route different pages for different browsers. The very simple script in Listing 6 sniffs for Netscape or Internet Explorer and allows you to redirect to a page specifically designed for one browser or the other. This makes it possible to use browser-specific technology when your audience would expect it without making other users feel left out.

Here's how to make it work:

• Design a page for Netscape Navigator. In the example script, I've named it nn_index.html.
• Design a page for Internet Explorer. I've named it msie_index.html in the example script.
• Create an index page with the sniff-and-route script included, as shown in Listing 6. Leave the body of the index page empty.

When I loaded the index page of my sample site with Microsoft Internet Explorer, it sent me immediately to the IE page, shown in Figure 3.

Figure 3. Thanks to the script in Listing 6, the index page sent me to this page that fits the browser I used to test it.


Tutorial Pages:
» Keep users happy by using savvy scripts
» Serving user needs
» Planning ahead
» The rock-bottom lowest-common-denominator
» Route for technology, not content
» Finding scripts or rolling your own
» Detecting the details
» Routing by browser type
» Matching pages to display resolution
» Testing your scripts
» Summing up
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Ask A Question
characters left.