↑
Main Page
Detecting Windows operating systems
After the platform is determined, it is then possible to determine some operating system information.
For Windows or Unix, you can actually pull out the operating system version. For Macintosh, however,
you cannot. The Macintosh platform provides information only if the processor is a 68000 chip or a
PowerPC, although Safari includes the string
“MacOS X”
(but then again, Safari runs only on MacOS X,
so is that really helpful?).
Typically, determining the platform alone is good enough for making appropriate JavaScript branches.
However, sometimes additional operating system information is important, and this script provides
for that.
First steps
So how does one go about determining the platform of the client user? Once again, the
navigator
object comes to the rescue with its
platform
property. But as usual, things aren’t as easy as they seem.
Indeed, each browser provides different information to
navigator.platform
. For instance, IE and
Netscape Communicator return
“Win32”
for Windows 32-bit systems,
“Mac68k”
or
“MacPPC”
(depend-
ing on the processor) for Macintosh systems. It returns the actual name of the operating system for Unix
systems. On the other hand, Mozilla returns
“Windows”
for all Windows systems,
“Macintosh”
for all
Macintosh systems, and
“X11”
for all Unix systems. So you have a lot of options to check for when
checking the client platform.
Checking for Windows and Macintosh systems is pretty straightforward; you just need to check for the
various strings:
var isWin = (navigator.platform == “Win32”) || (navigator.platform == “Windows”);
var isMac = (navigator.platform == “Mac68K”) || (navigator.platform == “MacPPC”)
|| (navigator.platform == “Macintosh”);
Because browsers return such varying values when a Unix platform is in use, it is necessary to make
sure that the platform isn’t Windows or Macintosh, and then check for
“X11”
as well:
var isUnix = (navigator.platform == “X11”) && !isWin && !isMac;
After you know what platform you are dealing with, you can try to determine which operating system is
being used.
Detecting Windows operating systems
It seems like every other year a new version of the Windows operating system is released. For a long
time, Microsoft has had two separate versions of Windows: one for home use and one for business use.
The home use version was called simply called Windows. The business version was called Windows NT.
Little overlap occurred between the two versions. The one exception, however, was the user interface. In
2001, Microsoft decided to merge the home and business versions into a new product, Windows XP. This
new operating system combines the stability and security of Windows NT with the user-friendliness of
traditional Windows.
245
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 245
Free JavaScript Editor
Ajax Editor
©
→