Main Page

Detecting Macintosh operating systems

|| sUserAgent.indexOf(“Windows ME”) > -1;
isWin2K = sUserAgent.indexOf(“Windows NT 5.0”) > -1
|| sUserAgent.indexOf(“Windows 2000”) > -1;
isWinXP = sUserAgent.indexOf(“Windows NT 5.1”) > -1
|| sUserAgent.indexOf(“Windows XP”) > -1;
}
Windows NT 4.0 is a bit more complicated, and it is IE’s fault. It includes the string
“Windows NT”
only in
its user-agent string, which means that you cannot search on it alone. Why? Because IE identifies Windows
2000 as
“Windows NT 5.0”
and Windows XP as
“Windows NT 5.1”
. If you simply searched for
“Windows NT”
, the result would be true for all three, and that is not preferred behavior. So for Windows
NT 4.0, you have to search for
“Windows NT”
,
“WinNT”
,
“WinNT4.0”
, and
“Windows NT 4.0”
and then
make sure that it isn’t the other versions of Windows:
if (isWin) {
isWin95 = sUserAgent.indexOf(“Win95”) > -1
|| sUserAgent.indexOf(“Windows 95”) > -1;
isWin98 = sUserAgent.indexOf(“Win98”) > -1
|| sUserAgent.indexOf(“Windows 98”) > -1;
isWinME = sUserAgent.indexOf(“Win 9x 4.90”) > -1
|| sUserAgent.indexOf(“Windows ME”) > -1;
isWin2K = sUserAgent.indexOf(“Windows NT 5.0”) > -1
|| sUserAgent.indexOf(“Windows 2000”) > -1;
isWinXP = sUserAgent.indexOf(“Windows NT 5.1”) > -1
|| sUserAgent.indexOf(“Windows XP”) > -1;
isWinNT4 = sUserAgent.indexOf(“WinNT”) > -1
|| sUserAgent.indexOf(“Windows NT”) > -1
|| sUserAgent.indexOf(“WinNT4.0”) > -1
|| sUserAgent.indexOf(“Windows NT 4.0”) > -1
&& (!isWinME && !isWin2K && !isWinXP);
}
And there you have it. You have successfully detected the various Windows operating systems.
Detecting Macintosh operating systems
Believe it or not, this is actually an easy part of the trek into the client’s machine. Traditionally, Macintosh
browsers would not tell you the operating system being used; the only information they provided was
whether the Macintosh was using a 68000 processor or a PowerPC processor. Only recently have browsers
begun to report the MacOS X as the operating system, meaning that testing for MacOS X is trustworthy
if you find “MacOS X” in the user-agent string. If it’s not there, however, the user could still be using
MacOS X but not have a browser that reports it. For this reason, it’s best to stick to the old method of
checking the processor.
The following table shows the strings that each browser includes in its user-agent string to indicate the
processor being used:
IE
NS4
Mozilla
Opera
MacOS (68k) “Mac_68000”
“68K”
“68K”
N/A
MacOS (PPC) “Mac_PowerPC” “PPC” “PPC”
“Mac_PowerPC”
247
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 247


JavaScript EditorFree JavaScript Editor     Ajax Editor


©