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.
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.
The major changes in the new 2006-2007 edition are listed here:
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.
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.
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.
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.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:
Normally the "gecko" family browsers are stating a particular release version number in the user agent string,
prepositioned by the abbreviation "rv:".
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.
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.
call and apply methods of functions (and
fulfills the 1.2 requirements below).
©
2006-2007 The Script IS LICENSED (MPL).