Description: This browser sniffer detects all the major browsers currently out there, and passes the results on as variables to facilitate your browser detection needs. It differentiates between Windows, Mac and Linux, and the most commonly used DHTML browsers - IE4/5/6, Netscape 4/6/7/other Gecko, Konqueror 2.2+, Safari, Opera 5/6/7. All other browsers are grouped together under a single exclude variable, to protect them from complex scripting.

Directions: Simply paste the following script at the beginning of the <HEAD> section, so that other scripts on the same page can have access to its variables. If you use it on more than one page, consider saving the script as an external .js file, so that it caches:

Select All

Variables from the script

The script returns a set of browser variables (Below are live results dependant on your browser type):

Underpinning these is a safety variable, for protecting legacy browsers:

There are also three OS variables:

and you can query a lower-case version of the user agent string:

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 browsers, 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:

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 (ns6||op7) { ... gecko, KTHML or Opera 7 ... }
    else if (ie5) { ... internet explorer 5+ ... }
    else { ... any other dhtml browser ... }

There are several minor browsers which have enough DHTML support to pass one of the object tests, but not enough to be useful.
The script specifically filters out (adds to the exclude group) - Espial Escape, ICEBrowser and OmniWeb.