Script ua.js (anew)

The original script was published in 2002. It hasn't been updated since 2003. This is an attempt to revive the basic concept and make the script useful anew.

Source

ua.js

Background

The script's source file is a Contributor Version of the source file formerly located at <http://devedge.netscape.com/toolbox/examples/2002/xb/ua/ua.js> but then (temporarily) moved to <http://devedge-temp.mozilla.org/toolbox/examples/2002/xb/ua/ua.js>.
Below is the description quoted in full from the original manpage:

xbDetectBrowser() is called when the script ua.js is loaded. It sets several properties on the window.navigator object which detail the kind of browser being used as based upon the reported navigator.userAgent string.

Please note that Object based sniffing is preferrable in most cases to using detection based upon the navigator.userAgent string. Many browsers, Gecko and Opera for example, can be configured to report any User Agent String. Opera even changes the DOM they support depending upon whether the user has set their User Agent string to an IE compatible setting. In addition, Object based sniffing will support any Browser which supports the approprioate objects while User Agent string based sniffing will only detect specific browsers.

However, there are situations, for example when you need to distinguish between versions of the same browser, where User Agent string based sniffing is appropriate.

Changes

The major changes in the new 2006-2007 edition are listed here:

Example

This script application example will render a table to show the name, value, a short description and type of each property created by the script.

Settings by ua.js

function xbDetectBrowser()

This function should work with all browsers complying with JavaScript from language version 1.0, i.e. Netscape Navigator 2, Internet Explorer 3, Opera 3 etc. When the source code is placed in – or the source file called from – the <head> section of a document, it is initiated before the document <body> has begun to load.

navigator properties added

There are nine properties added on the window.navigator object, but three of those are kept for backwards compatibility only and are therefore struck through in the listing.

The families and kinship relations

Due to shared or similar program source code, the main browsers are grouped into so-called families, browsers belonging to a particular family presumed to behave consistently from a web designer’s point of view. Different versions of a browser within a family can be distinguished by the navigator.version property.

Some of the "old" families are by now as well to be considered obsolete, but we keep them for backwards compatibility in the navigator.family property. A more relevant concept is the rendering engine used by a particular browser. We currently distinguish between Gecko, Trident, Presto and Apple Web Kit engines, which are covered by the navigator.engine property. If the browser is not built around one of those rendering engines, the property will fall back upon the family name.

A few vendors (notably Opera) are using the always applicable navigator.appName and navigator.appVersion properties for spoofing purposes. Occasionally there might be a benefit to let the script believe in the spoof. The navigator.kin property is simply combining those predefined properties to identify the application.

navigator.kin
Returns a string resolved by the concatenation navigator.appName + '/' + parseInt(navigator.appVersion). This way the resulting string would be "Microsoft Internet Explorer/4" if Internet Explorer was used. To simplify matters, the script will instead return "MSIE/4". A few examples:
navigator.family
Returns a string, which will be empty if the browser doesn't belong to one of the families listed. The formerly possible values hotjava and aol are removed. Possible values:
navigator.engine
Returns a string, which will be empty if the browser doesn't belong to a family as of above. Currently possible values:
navigator.version
Returns a number, which will be a floating point number from the number part of the navigator.appVersion property, if the browser doesn't belong to one of the families listed or belongs to the "java" family. So, for browsers where navigator.family is other than empty, the property will be the navigator.engine related version number as seen in the list:

Gecko specific version

Normally the "gecko" family browsers are stating a particular release version number in the user agent string, prepositioned by the abbreviation "rv:".

navigator.rv
Returns a string, which is identical with the release version number if it exists and the navigator.family value is gecko. If not, the property is empty:
navigator.rversion
Returns a number, which is the release version number in double floating points if the navigator.rv value is other than empty. If not, the property is 0.

Cosmetic properties

The script will scan the user agent string to find the best fit for the browser's popular (brand) name and version. The corresponding properties can be useful in alerts or short messages communicated to a web site's visitors.

navigator.prettyName
Returns a string, usually identical with the first or last word(s) of navigator.userAgent
navigator.prettyVersion
Returns a string, which is identical with the number put in relation with navigator.prettyName.

The script engine

An innovation in the new edition of the ua.js script is the investigation into the capacities of the script engine. The corresponding property can be useful to prevent simpler script engines from trying to interpret too complex script code. A particular navigator.js value may be applied as a minimum condition instead of the <script> deprecated attribute language="javascript1.x" in HTML.

navigator.js
Returns a number for the evaluated client-side JavaScript language version up to version 1.3. (Testing beyond that point would necessarily break simpler script engines.)

top of page


Valid ISO-HTML © 2006-2007 The Script IS LICENSED (MPL).