spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / designing / chap6 / 3 To page 1To page 2current page>
[previous]

Designing with JavaScript, 2nd Edition

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Beyond the browser

JavaScript is not limited to detecting just browsers and plug-ins; it can also determine the operating system on which a browser is running. As we saw back in Table 6-2, the navigator.appVersion property includes information about the operating system as well. Table 6-3 shows appVersion values for some common operating systems (the browser version information has been taken out, because it is irrelevant to our purpose here).

Operating system appVersion
Windows 2000 Windows NT 5.0; U
Windows 98 Win98; U
Windows 95 Win95; I
Windows 3.1 Win16; I
Macintosh PPC Macintosh; I; PPC
Linux (Unix) X11; U; Linux

Table 6-3: appVersion values for common operating systems

With this knowledge, you can create simple functions to determine which operating system a visitor is using. Example 6-12 shows a function that uses indexOf() to determine if a browser is running on Windows 98.

function isWin98() {
    if (navigator.appVersion.indexOf("98") != -1) {
        return true;
    }
    else {
        return false;
    }
}

Example 6-12: Is the platform Windows 98?

You can use this function, which returns true if the browser is running on Windows 98, to tailor parts of your page, just as you did with the browser detection script. For example:

if (isWin98()) {
    document.write("You're running Windows 98");
}
Pesky details  

Navigator and IE report Windows 98 as "Win98" and "Windows 98", respectively. Searching for "98" bridges the gap.

 

If the platform is Windows 98, the script prints "You're running Windows 98".

Think of it this way: if it's in the appVersion, you can detect it. This ability opens up many doors. For example, say your company develops software for a number of different operating systems. When visitors come to your site to download software, you can save them the trouble of specifying their operating system by doing it for them with JavaScript.

You can also easily combine operating system detection and browser detection, or operating system detection and plug-in detection. They're all interchangeable. Never again will your visitors have to make decisions based on their software (and hardware); you can do it for them.


home / programming / javascript / designing / chap6 / 3 To page 1To page 2current page>
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: December 27, 2001
Revised: December 27, 2001


URL: http://webreference.com/programming/javascript/designing/chap6/3/4.html