WebReference.com - Part 1 of Chapter 6 from Designing with JavaScript (1/4)
[next] |
Designing with JavaScript, 2nd Edition
What browser is that knocking at my door?
Before you learn how JavaScript differentiates between one browser and another, you need to understand how JavaScript gets information from the browser. This applies to both Netscape Navigator and Internet Explorer.
The navigator object
| The navigator object provides information about the browser, regardless of whether the browser is Netscape Navigator, Internet Explorer, or any other browser. | |
JavaScript identifies browsers through the navigator object. Although "navigator" is
the name of Netscape's browser, it serves the same function in IE's implementation of JavaScript. You
can get a lot of information from the navigator object, and we'll cover it all in this chapter. Table
6-1 shows three of the more useful properties for getting information about browsers, versions, and
operating systems.
| Property | What it refers to |
navigator.appName |
The browser's name |
navigator.appVersion |
The browser's version |
navigator.userAgent |
The browser's "user agent"--the official term for a web browser or a web-capable reader, like a handheld device or WebTV |
Table 6-1: Properties of the browser object
Without any context, the significance of these properties may not be clear. Table 6-2 shows some examples of what you actually get when you use these properties on different browsers. Note that this list isn't comprehensive; it just shows the properties for a handful of configurations, including some that are mostly of historical interest.
| Browser | appName |
appVersion |
userAgent |
| Netscape 3.01 on a Mac | Netscape | 3.01 (Macintosh; I; PPC) | Mozilla/3.01 (Macintosh; PPC) |
| Netscape 4.0 on Windows 95 | Netscape | 4.0 (Win95; I) | Mozilla/4.0 (Win95; I) |
| Netscape 4.72 on Windows 98 | Netscape | 4.72 [en] (Win98; U) | Mozilla/4.72 [en] (Win98; U) |
| Netscape 6.01 on Windows Me | Netscape | 5.0 (Windows; en-US) | Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; m18) Gecko/ 20010131 Netscape6/6.01 |
| Internet Explorer 3.0 on Windows 95 | Microsoft Internet Explorer | 2.0 (compatible; MSIE 3.01; Windows 95) | Mozilla/2.0 (compatible; MSIE 3.01; Windows 95) |
| Internet Explorer 4.0 on Windows 95 | Microsoft Internet Explorer | 4.0 (compatible; MSIE 4.0; Windows 95) | Mozilla/4.0 (compatible; MSIE 4.0; Windows 95) |
| Internet Explorer 5.0 on a Mac | Microsoft Internet Explorer | 4.0 (compatible; MSIE 5.0; Macintosh; I; PPC) | Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) |
| Internet Explorer 5.5 on Windows Me | Microsoft Internet Explorer | 4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90) | Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90) |
| Internet Explorer 6.0 on Windows 2000 | Microsoft Internet Explorer | 4.0 (compatible; MSIE 6.0; Windows NT 5.0) | Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) |
Table 6-2: Navigator properties on different browsers
[next] |
Created: December 12, 2001
Revised: December 12, 2001
URL: http://webreference.com/programming/javascript/designing/chap6/1/


