Variables from the sniffer script
The script incorporates a client sniffer, which returns a set of browser variables:
var | returns | Description |
ie | Internet Explorer 4+ and IE-based third-party browsers. You can also be more specific: | |
ie4 | ... Internet Explorer 4 only. | |
ie5 | ... Internet Explorer 5 or 6. | |
ie6 | ... Internet Explorer 6 only. | |
ns4 | Netscape 4 | |
ns6 | Gecko and KDE-based browsers - which includes Nestcape 6 and 7, Mozilla, Konqueror and Safari. You can also identify smaller groups within this: | |
ns7 | ... Netscape 7. | |
mz7 | ... any gecko browser except Netscape. This is principally designed to identify Mozilla's own builds from Version 0.6 onwards, but it also returns true for any other non-netscape gecko browser. | |
kde | ... Konqueror, from KDE 2.2 onwards. | |
saf | ... Safari. | |
op5 | Opera 5 | |
op6 | Opera 6 | |
op7 | Opera 7
These variables will identify Opera irrespective of which browser it's set to identify as. | |
Underpinning these is a safety variable, for protecting legacy browsers:
exclude | ||
There are also three OS variables:
win | Windows | |
mac | Mac OS | |
lin | Linux, or anything else |
and you can query a lower-case version of the user agent string:
agt | ||
The sniffer variables are global, and therefore available to
any other scripts on the same page. They allow you to code for or exclude specific browers, eg:
if (mac&&ie5) { ... internet explorer 5 on a mac ... }
if (!ns4) { ... not netscape 4 ... }
if (win&&(op5||op6)) { ... a windows version of opera 5 or 6 ... }
if (ie5||ns6||op7) { ... ie5+, gecko, kde or opera 7 ... }Remember that some browsers return true for more than one variable:
(ie6) and also for (ie)
(ie5) and also for (ie)
(ie4) and also for (ie)
(kde) and also for (ns6)
(saf) and also for (ns6)
(mz7) and also for (ns6)
The exclude variable returns true for all
unspecified browsers. This is very useful for protecting them from scary DHTML, eg:
if (!exclude) { ... modern browsers only ... }You may find it necessary to use a combination of expressions to get to the browser you need, eg:
if (!exclude) {
if (ie5) { ... internet explorer 5+ ... }
else { ... any other dhtml browser ... }
}But in many cases, old browsers can be excluded simply by using a version-specific tag, eg:
<script language="javascript1.2">This method is not foolproof - Opera 3, for example, does have limited support for js1.2, so will read
the script but likely make a mess of it. It's best to use a version-specific tag and
the exclude variable, and test in all browsers you're concerned with.
I admit I have a soft spot for Netscape 3 ... it reminds me of old rave music ...