• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Browser Feature Detection > 5.5. Detecting the Client Operating System

Detecting the Client Operating System

NN 2 , IE 3

Problem

You want to apply styles or other content features tailored to a particular operating system.

Solution

The string returned by the navigator.userAgent property usually contains information about the basic operating system platform on which the browser is running. Unfortunately, there is no standard nomenclature that you can search the userAgent string for a particular operating system. The values are not only different with each browser brand, but have evolved over time and may be different for OEM versions of the browser.

The widest difference is in the depiction of the Windows platforms, in which Windows 98, for example, might be displayed as “Win98” or “Windows 98”. A better solution is to test for the presence of strings that identify other operating systems more uniformly. For instance, all Macintosh versions have the string “Mac” somewhere in the navigator.userAgent property. By the same token, all Windows versions have the string “Win” in them, but that could be anything from Windows 3.1 to Windows XP. Furthermore, all Unix versions of Navigator have the string “X11”. If you’re just looking for a rough cut, the following global variable assignment statements will do the job of setting Boolean flags:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint