The navigator Object


The navigator Object

The navigator object, also called the clientInformation object in IE4+, refers to the browser itself. In early versions of the Netscape Navigator, the navigator object actually functioned as the top-level object, although that role has now been taken over by the window object. As we've already seen in earlier chapters, the navigator object is often a very useful one in cross-browser programming. We've used the navigator object's appName , appVersion , and userAgent properties to get information about the browser as far back as Chapter 1, "Essential JavaScript," as with this script (Listing 01-07.html on the web site) which displays the values of those properties:

 <HTML>      <HEAD>          <TITLE>              Checking Your Browser Type          </TITLE>      </HEAD>      <BODY>          <SCRIPT LANGUAGE="JavaScript">  document.write("navigator.appName: " + navigator.appName)   document.write("<BR><BR>")   document.write("navigator.appVersion: " + navigator.appVersion)   document.write("<BR><BR>")   document.write("navigator.userAgent: " + navigator.userAgent)  </SCRIPT>          <H1>Checking Your Browser Type</H1>      </BODY>  </HTML> 

You can see the results of this script in Chapter 1; Figure 1.12 shows the results for the Internet Explorer, and Figure 1.13 shows the results for the Netscape Navigator. Note that even though I'm using Internet Explorer 6.0 in Figure 1.12, the appVersion property shows a value of 4.0; and even though I'm using Netscape Navigator 6.2 in Figure 1.13, the appVersion property shows a value of 5.0. As you can see, the appVersion property is not the one to use to get the actual browser version. You've got to dig that information out of the userAgent property, as we will in this chapter.

You'll find the properties and methods of the navigator object in Table 10.1. (It has no events.) Not all properties and methods are supported in all browsers, of course.

Table 10.1. The Properties and Methods of the navigator Object

Properties

Methods

appCodeName

javaEnabled

appMinorVersion

preference

appName

taintEnabled

appVersion

 

browserLanguage

 

cookieEnabled

 

cpuClass

 

language

 

mimeTypes

 

onLine

 

oscpu

 

platform

 

plugins

 

product

 

productSub

 

securityPolicy

 

systemLanguage

 

userAgent

 

userLanguage

 

userProfile

 

vendor

 

vendorSub

 

It's time to take a look at this object in depth, starting with its properties.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net