esdras
asked on
How do I detect Windows NT with javascript?
I am able to detect win3.1, win95, and macs using the following script:
<script language="javascript">
if (navigator.appVersion.inde xOf("95") != -1)
document.write('<font size="3"><b>Windows 95</b></font>');
else if (navigator.appVersion.inde xOf("PPC") != -1)
document.write('<font size="3"><b>Apple PC</b></font>');
else if (navigator.appVersion.inde xOf("16") != -1)
document.write('<font size="3"><b>Windows 3.1</b></font>');
</script>
what "navigator.appVersion.inde xOf() can I use to detect Windows NT?
Thanks!
Jonathan
<script language="javascript">
if (navigator.appVersion.inde
document.write('<font size="3"><b>Windows 95</b></font>');
else if (navigator.appVersion.inde
document.write('<font size="3"><b>Apple PC</b></font>');
else if (navigator.appVersion.inde
document.write('<font size="3"><b>Windows 3.1</b></font>');
</script>
what "navigator.appVersion.inde
Thanks!
Jonathan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A valid point - Communicator is the first version of Netscape (or any other browser I'm aware of) that does, in fact, have an NT-specific version - but it's entirely possible to run the W96 version on an NT box or vice versa.
Another note from "in the meantime" - I've been goofing around a bit at home, running Windows in emulation mode on a Mac, and the appVersion identified me as a WindowsNT user. What fun! I suppose the same thing would happen on a UNIX terminal emulating windows, etc.
Another note from "in the meantime" - I've been goofing around a bit at home, running Windows in emulation mode on a Mac, and the appVersion identified me as a WindowsNT user. What fun! I suppose the same thing would happen on a UNIX terminal emulating windows, etc.
All of the following are on NT4 workstation.
Netscape Navigator 4:
4.03 [en] (WinNT; U ;Nav)
Internet Explorer 3.02:
2.0 (compatible; MSIE 3.02; Windows NT)
Netscape Navigator 3:
3.0Gold (WinNT; I)
The browser seems to have some sense typically as to what platform it's running on, but as indicated before can't be trusted completely. So to answer the original question: if absolute reliability isn't important, it seems you should use the following:
else if (navigator.appVersion.inde xOf("WinNT ") != -1
|| navigator.appVersion.index Of("Window s NT") != -1)
document.write('<font size="3"><b>Windows NT</b></font>');
Netscape Navigator 4:
4.03 [en] (WinNT; U ;Nav)
Internet Explorer 3.02:
2.0 (compatible; MSIE 3.02; Windows NT)
Netscape Navigator 3:
3.0Gold (WinNT; I)
The browser seems to have some sense typically as to what platform it's running on, but as indicated before can't be trusted completely. So to answer the original question: if absolute reliability isn't important, it seems you should use the following:
else if (navigator.appVersion.inde
|| navigator.appVersion.index
document.write('<font size="3"><b>Windows NT</b></font>');
What are you going to do with this?
It is correct that you can't be 100% sure what platform/browser the user is on. But when you use javascript you can never be anywhere close to 100% sure the code will execute properly or at all, so for many purposes it's ok.