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


Detecting the details

This detailed script demonstrates the kinds of information JavaScript can glean from behind-the-scenes. I'll break it down first so you can see how it works, then put it together in a usable format.

The script begins by detecting the Operating System and stores that information so it can be used later, as shown in Listing 1.

Listing 2 shows the part of the script that defines variables that assign information from the browser to the script results.

Listing 3 collects additional information that's available only from 4.0 browsers. It's a sniff for more detailed information. (Cookies respond only to Internet Explorer 4.0 browsers and above, and the CPU test returns an unknown in Navigator.)

To test the script, add the contents of Listing 4 to the body of an HTML document and then view the HTML document in a variety of browsers. I've included some HTML to make the resulting code attractive (and legible in the reduced image used in Figure 1 and Figure 2).

The whole script within the context of a complete HTML document appears in Listing 5.

Figure 1 and Figure 2 show the results of using the script in Listing 4 and loading the page with Windows Internet Explorer 5.0 and Macintosh Netscape Navigator. The script demonstrates in detail the kind of information that can be detected using JavaScript.

Figure 1. This is what you see if you load the test page with Internet Explorer on a Windows 98 PC


Figure 2. Compare the results of loading the test page with a Mac of recent vintage running Netscape Navigator


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