Click to See Complete Forum and Search --> : System Performance Advise Ad


ecross
07-31-2003, 09:30 AM
Is there a script that will detect which version of Windows you are using? For example, if you're running Windows XP, then if some javascript detects the OS, then a message will appear? I get the System Performance Advise ads and it always detects the correct OS I'm using.

When I was on a Win2000 Machine, it detect Windows 2000. Now, it's detecting Windows XP. Here is what I'm talking about....

Fang
07-31-2003, 12:49 PM
If you look at the javascript on their site you will see exactly how then do it!

ecross
07-31-2003, 01:43 PM
Okay, there is a external file called useragent.js. I modified it because there was a lot of junk that I didn't want to see. Now, when I open a webpage that is saved onto my computer, I get the following:

\par \par You are using Windows XP.

What is the \par about?

I changed the file extension to a text file so I can show you the code. In my webpage, I'm using these lines:

<html>
<body>
You are using
<script language="Javascript">
<!--This is the detect script
document.writeln(sUserAgent);
-->
</script>
</body>
</html>

Nevermore
07-31-2003, 01:49 PM
http://javascriptkit.com/script/cut22.shtml

Fang
07-31-2003, 02:03 PM
Just strip away all the document.writeln stuff:



<script type="text/javascript">
<!--
var sUserAgent;
var agt=navigator.userAgent.toLowerCase();
var bWindows = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var bWindows95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var bWindowsme = ((agt.indexOf("win 9x 4.90")!=-1));
var bWindows2k = ((agt.indexOf("windows nt 5.0")!=-1));
var bWindowsXP = ((agt.indexOf("windows nt 5.1")!=-1));
var bWindows98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var bWindowsnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
if (bWindowsXP == true)
sUserAgent = 'Windows XP';
else
if (bWindows2k == true)
sUserAgent = 'Windows 2000';
else
if (bWindowsme == true)
sUserAgent = 'Windows Me';
else
if (bWindowsnt == true)
sUserAgent = 'Windows NT';
else
if (bWindows95 == true)
sUserAgent = 'Windows 95';
else
if (bWindows98 == true)
sUserAgent = 'Windows 98';
else
sUserAgent = 'Non-Windows 98';
document.write(sUserAgent);
//-->
</script>