Main Page

The Platform/Operating SystemDetection Script

Adding these checks to the code, you get the following:
var isNS4 = !isIE && !isOpera && !isMoz && !isKHTML
&& (sUserAgent.indexOf(“Mozilla”) == 0)
&& (navigator.appName == “Netscape”)
&& (fAppVersion >= 4.0 && fAppVersion < 5.0);
This variable accurately determines if the browser is Netscape Communicator. Next you want to deter-
mine the minimal versions. For this, you should check for version 4.0, 4.5 (which was a major release
with lots of code improvements), 4.7 (another major release), and 4.8 (the last release).
var isMinNS4 = isMinNS4_5 = isMinNS4_7 = isMinNS4_8 = false;
And because Netscape Communicator stores its version number in a logical way, it is very easy to deter-
mine the values for these variables:
if (isNS4) {
isMinNS4 = true;
isMinNS4_5 = fAppVersion >= 4.5;
isMinNS4_7 = fAppVersion >= 4.7;
isMinNS4_8 = fAppVersion >= 4.8;
}
The first variable,
isMinNS4
, is automatically set to
true
because this was one of the tests performed
when calculating
isNS4
. All the other minimal versions must be checked for in the normal way.
This completes the browser detection portion of the script. Next up is platform and operating system
detection.
The Platform/Operating System
Detection Script
Now that you have delved into the world of browser detection at great length, you must meet another
challenge: figuring out the operating system on the client’s machine. Even though the browser compa-
nies say that their browsers act the same across different platforms and operating systems, it is not so.
Take the case of Internet Explorer. On Windows, a powerful interface allows Microsoft ActiveX controls
to be embedded in pages or used in JavaScript. The problem is that these ActiveX controls require
Windows to work. So even though Microsoft says that IE on Unix and Macintosh works the same as IE
on Windows, you know that this is impossible. Therefore, you must, at least, be able to tell which operat-
ing system you are dealing with in order to determine if special accommodations must be made.
Methodology
The method for determining the operating system is to start by looking for the platform. For the pur-
poses of this book, the platforms are divided into three groups: Windows, Macintosh, and Unix.
244
Chapter 8
11_579088 ch08.qxd 3/28/05 11:38 AM Page 244


JavaScript EditorFree JavaScript Editor     Ajax Editor


©