Solved

How do I detect Windows NT with javascript?

Posted on 1997-11-20
5
299 Views
Last Modified: 2012-06-27
I am able to detect win3.1, win95, and macs using the following script:

<script language="javascript">
if (navigator.appVersion.indexOf("95") != -1)
document.write('<font size="3"><b>Windows 95</b></font>');
else if (navigator.appVersion.indexOf("PPC") != -1)
document.write('<font size="3"><b>Apple PC</b></font>');
else if (navigator.appVersion.indexOf("16") != -1)
document.write('<font size="3"><b>Windows 3.1</b></font>');
</script>

what "navigator.appVersion.indexOf() can I use to detect Windows NT?

Thanks!
Jonathan
0
Comment
Question by:esdras
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
jshamlin earned 50 total points
Comment Utility
You're stuck - the appVersion doesn't tell you what operating system the user has, only the operating system the *browser* was designed for.  Windows NT use the same applications (by and large) as Win95 - so when you check for indexOf("95"), an NT box will return the same value as a Win95 box (in fact, there is no NT-only version of Netscape).  it's also entirely possible that there are a few gormless individuals running 16-bit browsers in emulation mode on their Win95 boxes.

You'll have the same problem distinguishing between Mac users - who's on 68040 using System 6 and who's on a PPC using Rhapsody
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Well... not necessarily. I was in fact noticing the other day that my Netscape 4.03 on WinNT did in fact identify itself as NT in the user agent string. I am not on that machine right now or I'd put the value here, I will later if noone else does in the interim.

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.
0
 
LVL 4

Expert Comment

by:jshamlin
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
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.indexOf("WinNT") != -1
      || navigator.appVersion.indexOf("Windows NT") != -1)
 document.write('<font size="3"><b>Windows NT</b></font>');
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
What are you going to do with this?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now