Main Page

Detecting Netscape Communicator 4.x

Depending on which browsers you plan on supporting, you may have different Mozilla versions. For
instance, Netscape 7 is based on Mozilla 1.0 whereas Netscape 7.1 is based on Mozilla 1.4. So, it makes
sense to test for these versions in case some users still have the Netscape-branded browsers. Mozilla 1.5
also is fairly popular, so that would be a good one to include as well:
var isMinMoz1 = sMinMoz1_4 = isMinMoz1_5 = false;
Once again, it is necessary to pull out the actual version number from the user-agent string. In Mozilla’s
case, the Mozilla version is located after the text
and can contain either one or two decimal points,
so a non-capturing group is also necessary here:
var reMoz = new RegExp(“rv:(\\d+\\.\\d+(?:\\.\\d+)?)”);
It is easy to detect the Mozilla version if you use this value and the
if (isMoz) {
var reMoz = new RegExp(“rv:(\\d+\\.\\d+(?:\\.\\d+)?)”);
isMinMoz1 = compareVersions(RegExp[“$1”], “1.0”) >= 0;
isMinMoz1_4 = compareVersions(RegExp[“$1”], “1.4”) >= 0;
isMinMoz1_5 = compareVersions(RegExp[“$1”], “1.5”) >= 0;
The last task is to properly detect Mozilla’s predecessor: the original Netscape browser.
Detecting Netscape Communicator 4.x
Although Netscape Communicator is a dinosaur in the light of today’s standards-compliant browsers,
it still has a pretty significant user base around the world.
To start, remember the user-agent string from Netscape Communicator 4.79:
Mozilla/4.79 (Win98; I)
As you can see, the user-agent string doesn’t specifically say that this is Netscape Communicator. All
other browsers include the string
in their user-agent strings, so you can’t just check for that.
The method for detecting Netscape Communicator 4.x is the same one used by Sherlock Holmes: If you
eliminate the impossible, whatever remains, however implausible, must be true. For the purposes of
browser detection, this means you must first determine all the browsers that the user isn’t using:
var isNS4 = !isIE && !isOpera && !isMoz && !isKHTML;
So far so good. Next, there are three additional things to check:
That the string “Mozilla” is at the beginning of the user-agent string (at position 0).
That the value of
That the value of
is greater-than or equal to 4.0, but less than 5.0 (this
value has already been stored in the variable
, created way back at the beginning
of the code).
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 243

JavaScript EditorFree JavaScript Editor     Ajax Editor