How to Use the Navigator Object in JavaScript - dummies

How to Use the Navigator Object in JavaScript

By John Paul Mueller

The navigator object provides support for a number of interesting properties and methods in JavaScript. All of these properties and methods tell you something about the browser used to access the page. Here’s a list of the most commonly supported properties for this object:

  • appCodeName: Provides the vendor’s codename for the product.

  • appName: Returns that commercial (released) name of the product. Unfortunately, the value returned is wrong in most cases.

  • appVersion: Theoretically returns the version number of the browser, but this information is incorrect in some situations.

  • cookieEnabled: Specifies whether the browser has cookie support enabled.

  • onLine: Specifies whether the browser is online. This is the setting for working offline rather than actually connecting to the network. In other words, the browser might not have a network connection and this property will still return true.

  • platform: Provides information about the platform for which the browser is compiled. This property doesn’t reflect the platform the browser’s currently executing on.

  • userAgent: Returns a specially formatted header that the browser returns to the server when making a request. This information may not actually reflect the browser functionality, but rather it may reflect how the browser wants to appear to the server.

  • This string is complicated to read and use. This explanation is helpful in discovering precisely how this string’s formatted.

The methods are equally useful. You can use them to detect browser support for certain functionality. In most cases, the browser offers the required feature, but the user may have turned it off. Here are the methods of interest:

  • javaEnabled(): Specifies whether the browser has Java support enabled.

  • taintEnabled(): Specifies whether the browser has data tainting enabled.

    Data tainting is a technique originally introduced by Netscape Navigator 3 — it allows one window to see the properties in another window. The idea is that the two windows can share data and developers can create more interesting applications.

    However, data tainting proved to be a huge security risk, and many people have it turned off even if their browser supports the feature (which isn’t likely in newer browsers). This TechRepublic article discusses data tainting, and other security issues, in greater depth.

Many browsers support other properties and methods that help you find out more about the browser and its functionality. These lists represent the commonly used properties and methods.