The JavaScript Diaries: Part 10
[next]
The JavaScript Diaries: Part 10
There are four objects that provide information about the environment of the
user's system. They belong to the window
object: navigator
,
screen
, history
and location
. These objects
are used to obtain information such as screen size and resolution, color depth
of the monitor, limited information on the browser history, and the URL. In
addition, information such as the user's operating system, including the browser
type, version and language can also be obtained.
In this installment, we'll look at objects, their related properties and methods. We'll delve deeper into them when we use them later in our study.
The navigator
Object
This object is used to obtain information about the type of browser being used to access the page. It's usefulness becomes apparent when the user needs to be directed to a different page or perform certain tasks, depending upon their browser:
Properties |
appCodeName appName appVersion cookieEnabled platform userAgent |
Properties
appCodeName
This property returns the internal name of the browse, but it's not really useful as it always returns Mozilla in Firefox, Netscape, IE, and Opera browsers.
appName
This property returns the 'official' name of the browser. IE returns Microsoft Internet Explorer and Firefox and Netscape both return Netscape. Since Opera users can change their browser's identity, it may appear as Netscape, Opera, or Microsoft Internet Explorer.
appVersion
This property returns the version number of the browser. However, it's not necessarily the actual version number, but an internal number. For instance, IE versions 4-6 are all shown as version 4.0 and Netscape 6 returns a version number of 5.0. In my version of Firefox, running browser version 1.07, it returns 5.0. That's because it's using the same Mozilla engine as Netscape. In addition, it may also return the operating system and the default language of the browser.
There are better ways of determining the version number. One way is to use object detection. We'll look at this and other methods later in this series.
cookieEnabled
This property is used to check if the browser will accept cookies. It could be used as follows:
if (navigator.cookieEnabled) { // code for cookie here }
platform
This property returns the operating platform on the user's computer. It might look something like "Win32" or "MacPPC." It doesn't give the version of the operating system.
[next]
Created: October 14, 2005
URL: