Main Page

Browser and OperatingSystem Detection

Browser and Operating
System Detection
A big part of Web programming is identifying target browsers and operating systems. Whether
you are building a simple Web site or a complex Web application, this important information must
be determined before any work begins. Because browsers support different levels of HTML and
JavaScript, often differing across operating systems, you can save time and money by knowing
your targets. This ensures that you won’t include features that aren’t available to your users.
Today, the challenge is even greater with the vast number of Web browsers available on so many
different platforms. Windows users can use Internet Explorer, Mozilla, and Opera; Macintosh
users have Internet Explorer, Mozilla, and now, Safari; Unix users can use Mozilla as well as
Konqueror. Developing for all of them requires a great deal of forethought and a well-planned
approach to dealing with their similarities and differences.
This chapter gives you an in-depth look at JavaScript browser and operating system detection to
prepare you to develop cross-browser solutions.
The Navigator Object
The most important object in client-side browser detection is the
navigator
object. The
naviga-
tor
object is one of the earliest BOM objects implemented (beginning in Netscape Navigator 2.0
and Internet Explorer 3.0). As I mentioned in Chapter 5, “JavaScript in the Browser,” it contains a
number of properties that can give you information about the browser, such as the name, version,
and platform.
Although Microsoft objected to the term
navigator
as being specific to Netscape’s browser, the
navigator
object has become a sort of de facto standard for providing information about a Web
browser. (Microsoft does have its own object called
clientInformation
in addition to the
navigator
object, but they both provide similar data.)
11_579088 ch08.qxd 3/28/05 11:38 AM Page 225


JavaScript EditorFree JavaScript Editor     Ajax Editor


©