↑
Main Page
Windows XP
With that brief history lesson out of the way, many different versions of Windows are out there to detect:
?
Windows 95
?
Windows 98
?
Windows NT 4.0
?
Windows 2000
?
Windows ME
?
Windows XP
Luckily, the operating system information is included in the user-agent string, meaning that the browser
gets to decide exactly what is displayed. The following table shows the different strings that are
included in the user-agent string depending on the operating system being used:
IE4+
NS4x
Mozilla
Opera pre-6 Opera 7+
Windows 95
“Windows “Win95” “Win95” “Windows “Windows
95”
95”
95”
Windows 98
“Windows “Win98” “Win98” “Windows “Windows
98”
98”
98”
Windows NT 4.0 “Windows “WinNT” “WinNT4.0” “Windows “Windows
NT”
NT 4.0”
NT 4.0”
Windows 2000 “Windows “Windows “Windows “Windows “Windows
NT 5.0” NT 5.0” NT 5.0”
2000”
NT 5.0”
Windows ME
“Win
“Win
“Win
“Windows “Win 9x
9x 4.90” 9x 4.90” 9x 4.90”
ME”
4.90”
Windows XP
“Windows “Windows “Windows “Windows “Windows
NT 5.1” NT 5.1” NT 5.1”
XP”
NT 5.1”
This task begins just like the task of detecting browser versions, by defining some variables:
var isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = false;
In order to determine each version of Windows, you must check the user-agent string for each value in a
row from the previous table. For example, if you want to check for Windows 98, you must check the
user-agent string for
“Windows 98”
and
“Win98”
, which covers all four browsers.
The easiest checks are for the Windows 95, 98, ME, 2000, and XP because they have only two values:
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
246
Chapter 8
11_579088 ch08.qxd 3/28/05 11:38 AM Page 246
Free JavaScript Editor
Ajax Editor
©
→