Ryan Gaffuri wrote:
I know that this works. I just don't get the syntax.
I know its checking the OS. just not sure how it works.
var v = navigator.appVersion.toUpperCase()
if (1+v.indexOf('WIN98')
os = 'Win98';
else if (1+v.indexOf('WINNT')
os = 'WinnT';
etc....
ok I know that v is set to whatever the value of the OS is.
Actually, v is set to the value of navigator.appVersion.toUpperCase(),
which may or may not be the version of the browser your JavaScript is
running in, and may or may not contain the operating system being used.
Here are my values of navigator.appVersion.toUpperCase():
IE6SP1: 4.0 (COMPATIBLE; MSIE 6.0; WINDOWS NT 5.1; .NET CLR 1.1.4322)
Firefox 1.0PR: 5.0 (WINDOWS; )
Mozilla 1.7.3: 5.0 (WINDOWS; EN-US)
Opera 7.54 (set to "Identify as MSIE 6.0"): 4.0 (COMPATIBLE; MSIE 6.0;
WINDOWS NT 5.1)
Opera 6.05 (set to "Identify as MSIE 5.0"): 4.0 (COMPATIBLE; MSIE 5.0;
WINDOWS XP)
Netscape 4.78: 4.78 [EN]C-CCK-MCD 20011025 (WINDOWS NT 5.0; U) (it's a
custom build install using Netscape's CCK)
This is by no means a complete list of browsers in use, just a sampling
to demonstrate the variety of responses you can obtain from
navigator.appVersion. In each tested browser, the tests being done for
WIN98 and WINNT will not match anything in
navigator.appVersion.toUpperCase().
navigator.platform.toUpperCase() reports "WIN32" for each of the
browsers listed above (when running on Windows)
navigator.appCodeName.toUpperCase() reports "MOZILLA" for each of the
browsers listed above
navigator.userAgent.toUpperCase() provides slightly more information for
a couple of browsers:
Firefox 1.0PR: MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; RV:1.7.3)
GECKO/20040913 FIREFOX/0.10
Mozilla 1.7.3: MOZILLA/5.0 (WINDOWS; U; WINDOWS NT 5.1; EN-US; RV:1.7.3)
GECKO/20040910
But navigator.userAgent is highly unreliable since it can be one of 5
values in Opera, and practically anything in Firefox/Mozilla.
In general, any information obtained by any property of the navigator
object is of little use on the public Internet. It may be of slightly
more value in the controlled environment of a corporate Intranet, where
you can be assured that a particular appVersion or userAgent actually
means the user is using a particular Windows version or
navigator.language means that the corporate user is in a particular part
of the world.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq