↑
Main Page
navigator object
alert(location);
alert(location.href);
The navigator object
The
navigator
object is one of the earliest implemented BOM objects, introduced in Netscape
Navigator 2.0 and Internet Explorer 3.0. It contains a significant amount of information about the
Web browser. It is also a property of the
window
object, and as such, can be referenced either as
window.navigator
or just
navigator
.
Although Microsoft originally 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 both provide the exact same data.)
Once again, the lack of standards rears its ugly head with the
navigator
object because each browser
decides what properties and methods to support. The following table lists the most popular properties
and methods and also which of the four most popular browsers — Internet Explorer, Mozilla, Opera,
and Safari — support them.
Property/Method Description
IE Moz Op Saf
appCodeName
String representing code name of the browser
X X X X
(typically
“Mozilla”)
appName
String representing official browser name
X X X X
appMinorVersion
String representing extra version information
X – – –
appVersion
String representing the browser version
X X X X
browserLanguage
* String representing the language of the browser X – X –
or operating system
cookieEnabled
Boolean indicating if cookies are enabled
X X X –
cpuClass
String representing the CPU class
(“x86”
,
X – – –
“68K”
,
“Alpha”
,
“PPC”
, or
“Other”
)
javaEnabled()
Boolean indicating if Java is enabled
X X X X
language
String representing language of the browser
– X X X
mimeTypes
Array of mimetypes registered with the browser – X X X
Table continued on following page
Throughout this section, the
location
object has been used in the examples.
Remember, the
location
object is a property of both
window
and
document
, so
window.location
and
document.location
are equal to each other and can be used
interchangeably.
155
JavaScript in the Browser
08_579088 ch05.qxd 3/28/05 11:37 AM Page 155
Free JavaScript Editor
Ajax Editor
©
→