This script source file uses various detection techniques and a number of functions to set a number of
properties for the envir and navigator objects.
Check out the Browser Sniffing Example!
The navigator object
function xtraNavigatorProperties()
This function is partly derivative work on the now dated Practical Browser Sniffer. It works
with all browsers properly implementing JavaScript language versions 1.0 and up. It is executed
instantly, i.e. before the document <body>
has begun to load.
Properties added to the navigator object
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.
We currently distinguish between Gecko, Trident, Presto and
AppleWebKit engines, which are covered by the navigator.engine property. Different
versions of a browser within a family can be distinguished by the navigator.version property.
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:
-
"MSIE/4" Internet Explorer 4 and later and also Opera
spoofing as Internet Explorer
-
"Netscape/4" Netscape Navigator 4
-
"Netscape/5" Browsers belonging to the Gecko family such as Netscape
6 and later, Firefox, SeaMonkey, and Safari and other
browsers applying the AppleWebKit
-
"Opera/N" Opera browsers (if spoofing is not used) where
"N" represents the application version number integer 3, 4, 5, ... 9.
-
navigator.engine
-
Returns a lower case string, which will fall back to navigator.appCodeName if
the browser does not belong to one of the rendering engines listed or does not have a
navigator.product value. Current possible values:
-
"gecko" browsers based upon mozilla.org open source code, e.g. Netscape
6+, Firefox, SeaMonkey, Galeon, K-Meleon
-
"presto" Opera browsers versions 7 and later
-
"applewebkit" browsers applying the AppleWebKit, e.g. Safari,
OmniWeb
-
"trident" Internet Explorer versions 4 and later, Netscape Browser
8 when the trident plugin is applied
- the value for navigator.product converted to lower case
- falling back to navigator.appCodeName converted to lower case
-
navigator.version
-
Returns a number, which will fall back to a floating point number from the number part of
the navigator.appVersion property, if the browser doesn't belong to one of the rendering
engines. So, the property will normally be the navigator.engine specific version number as
seen in the list:
- "gecko" browsers return the build date from the navigator.productSub
property, such as 20071119 (but never including the hour of the build).
- "presto" browsers return the normal Opera version number.
- "applewebkit" browsers return the particular AppleWebKit build version number
converted to double floating points.
- "trident" browsers return the JScript version number.
- falling back upon the number part of navigator.appVersion
Release version
-
navigator.rversion
-
Returns a number, which is a particular release version number in double
floating points if such a release version number is available for the browser in question. If not, the
property will fall back on navigator.prettyVersion as its base.
- e.g. 1.080114 for Firefox 2.0.0.14 ("rv:1.8.1.14")
- e.g. 525.1303 for Safari 3.1 ("Version/3.1 Safari/525.13.3")
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, denoting the browser's popular name when it's detectable, falling back
to the first or last word(s) of navigator.userAgent.
-
navigator.prettyVersion
-
Returns a string, which is the number put in relation with
navigator.prettyName.
-
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.5.
-
1.5 The script engine can handle functions inside other functions (and fulfills the 1.3
requirements below).
-
1.3 The script engine is compliant with ECMAScript, edition 1, and has not
undefined values for the
call
and apply
methods of functions (and
fulfills the 1.2 requirements below).
-
1.2 The script engine has not undefined values for
navigator.platform and screen and has a way of determining the natural language of
the browser or system (and fulfills the 1.1 requirements below).
-
1.1 The script engine has not undefined values for
Date.prototype.getTimezoneOffset, navigator.javaEnabled,
navigator.mimeTypes and navigator.plugins.
-
1.0 Netscape Navigator 2, Internet Explorer before version 4
-
0 unknown version
The "x" properties
-
navigator.xScreenColor
-
The property returns a number which is a computed integer dependent on the screen's
colour resolution, where 2 represents a widely used (basic) resolution. Note that integers
greater than 4 is perfectly possible.
-
0 Screen resolution is less than 256 colours.
-
1 Screen resolution is 256 colours.
-
2 Screen resolution is 16-bits (high) colour.
-
3 Screen resolution is 24-bits colour.
-
4 Screen resolution is 32-bits (true) colour.
-
navigator.xScreenSize
-
The property returns a number which is a computed integer dependent on the screen's pixel
resolution, where 2 represents a widely used (basic) resolution. Note that integers greater than
4 is perfectly possible.
-
1 Screen resolution is at least 400 x 300 pixels.
-
2 Screen resolution is at least 800 x 600 pixels.
-
3 Screen resolution is at least 1200 x 900 pixels.
-
4 Screen resolution is at least 1600 x 1200 pixels.
There are also floating points returned. Here is a list of a few examples:
-
0.8 Screen resolution is 320 x 240 pixels ("TV").
-
1.6 Screen resolution is 640 x 480 pixels (VGA).
-
2.56 Screen resolution is 1024 x 768 pixels (XGA-2).
-
2.88 Screen resolution is 1152 x 864 pixels.
-
3.2 Screen resolution is 1280 x 1024 pixels (SXGA).
-
3.5 Screen resolution is 1680 x 1050 pixels (WSXGA+).
-
4.0 Screen resolution is 1920 x 1200 pixels (WUXGA).
-
5.12 Screen resolution is 2048 x 1536 pixels (QXGA).
-
navigator.xLanguage
-
Returns a string, which is based on navigator.language,
navigator.userLanguage or navigator.browserLanguage.
-
language-code, e.g "en" for English
- "" if not reported by the browser
-
navigator.xOS
-
Returns an array, consisting of three parts. The first part, called by
navigator.xOS[0]
, returns the four string values in the list:
- "win" for all Windows platforms
- "mac" for all Macintosh platforms
- "nix" for all Unix like platforms
- "" if platform is not one of the above
The second part, called by navigator.xOS[1]
, returns an OS or CPU
string value depending on the platform:
- for Windows normally:
- for Macintosh normally:
- for Unix like normally:
- "sun"
- "hpux"
- "alpha"
- "linux"
- "unixware"
- "reliant"
- "sinix"
- "freebsd"
- "aix"
- "sco"
- "mpras"
- "bsd"
- "dec"
- "os2"
- "vms"
- "" if unknown
The third part, called by navigator.xOS[2]
, returns a version number
for Windows only (and if certain):
-
6 Win Vista
-
5.2 Win 2003 Server
-
5.1 Win XP
-
5 Win 2000
-
4.9 Win ME
-
3/4 Win NT
-
0.98 Win 98
-
0.95 Win 95
-
0 uncertain case or another platform
-
navigator.xTimezone
-
Returns a number, corresponding to the timezone relative to GMT, and taking DST into
account, i.e. Central Europe will all year round return (+)1.
-
navigator.xJava
-
Returns a boolean value, depending on whether Sun Java (or equivalent) being
installed and enabled. (Microsoft Java does not apply.)
-
true Java is enabled.
-
false Java is disabled.
-
undefined (or null) if not applicable
-
navigator.xtypeShockwaveFlash
-
Checking if the browser is prepared to harbour a plug-in for the particular mime type. Notice that
"application/", "x-" and "-" in the type description are removed and the following character is in upper case
in the property name.
This is an example only. Any mime type might be inserted and checked for into the script file.
-
boolean depending on whether application/x-shockwave-flash occurs in
navigator.mimeTypes[ ]
-
undefined (or null) if not applicable
-
navigator.xplugShockwaveFlash
-
Checking if a plug-in is enabled for the particular mime type. Notice that "application/", "x-"
and "-" in the type description are removed and the following character is in upper case in the property
name.
This is an example only. Any plug-in might be checked for with the script.
-
boolean depending on whether application/x-shockwave-flash returns
true for navigator.mimeTypes[ ].enabledPlugin
-
undefined (or null) if not applicable
The envir object
function Envir()
This function is executed by the function Exami, which should be triggered only when the
corresponding document is fully loaded.
The primary properties:
-
envir.noenvir
-
The property indicates the absence of all other envir properties. The
boolean value is set to true if the application is not
ECMAScript compliant, hence no other properties of the envir object
are defined.
-
envir.java
-
-
boolean depending on whether any java is installed and enabled.
-
envir.CSS1
-
-
number, which typically is 0, 0.3, 0.6,
0.8 or 1 depending on browser support of CSS version 1.
-
envir.CSS2
-
-
number, which typically is 0, 0.5, 1,
1.2, 1.4, 1.6, 1.8, 1.9, 2
or 2.1 depending on browser support of CSS version 2.
-
envir.dhtml
-
-
boolean depending on whether the browser is at least 4th generation (versions 4+)
i.e. DHTML capable.
-
envir.common
-
-
boolean same as above, but also depending on whether the browser has
CSS1 (fully) implemented.
-
envir.standards
-
-
boolean depending on whether the browser is at least 5th generation (versions 5+)
i.e. W3C industry standards compliant.
-
envir.strict
-
-
boolean same as above, but also depending on whether the browser is to a great extent
ready for XHTML and CSS2, and if it's implementing compatiblity
mode.
The secondary property:
-
envir.dom
-
Creating this object and conditionally setting one property:
-
envir.dom.implemented
-
Describing the occurrence of any W3C DOM compliance (cp. the next paragraph)
-
false if the general user agent version - i.e. the so-called browser generation - is
less than 5.
function Dom( )
-
envir.dom.implemented
-
Describing the level of W3C DOM compliance reported by the browser
-
number corresponding to the level of the DOM: 0,
1, 2, or 3
-
envir.dom.html
-
-
0 if not supported
-
number corresponding to the level of HTML: 1 or 2
-
envir.dom.xml
-
-
0 if not supported
-
number corresponding to the level of XML: 1, 2, or
3
-
envir.dom.range
-
-
0 if not supported
-
number corresponding to the level of Range: 2
-
envir.dom.traversal
-
-
0 if not supported
-
number corresponding to the level of Traversal: 2
-
envir.dom.views
-
-
0 if not supported
-
number corresponding to the level of Views: 2
-
envir.dom.stylesheets
-
-
0 if not supported
-
number corresponding to the level of StyleSheets: 2
-
envir.dom.css
-
-
0 if not supported
-
number corresponding to the level of CSS: 2
-
envir.dom.css2
-
-
0 if not supported
-
number corresponding to the level of CSS2: 2
-
envir.dom.events
-
-
0 if not supported
-
number corresponding to the level of Events: 2
-
envir.dom.uievents
-
-
0 if not supported
-
number corresponding to the level of UIEvents: 2
-
envir.dom.mouseevents
-
-
0 if not supported
-
number corresponding to the level of MouseEvents: 2
-
envir.dom.mutationevents
-
-
0 if not supported
-
number corresponding to the level of MutationEvents: 2
-
envir.dom.htmlevents
-
-
0 if not supported
-
number corresponding to the level of HTMLEvents: 2
-
envir.dom.ls
-
-
0 if not supported
-
number corresponding to the level of LS: 3
-
envir.dom.lsasync
-
-
0 if not supported
-
number corresponding to the level of LS-Async: 3
-
envir.dom.validation
-
-
0 if not supported
-
number corresponding to the level of Validation: 3
function Exami()
The Exami function is strictly for the script code's execution.