Detect the Operating System

Here is how to detect the Operating System(OS) the client is using. It will work on both IE and NN. This larger script stores a two digit abbreviation for the OS in the variable "clientos" for you to reference. The valid two digit operating systems that will be reported when variable "clientos" is referenced are:

For Windows: "31", "95", "98", "NT", "2K"(2000) or "XP"
For Macintosh: "MA"
For OS/2: "OS"
For Unix and Others: "UN"

<script type="text/javascript"> <!-- var clientos = "UN" var tv = navigator.appVersion.toUpperCase(); if (tv.indexOf("WIN") != -1) { clientos = "31"; if (tv.indexOf("98") != -1) clientos = "98" if (tv.indexOf("95") != -1) clientos = "95" if (tv.indexOf("NT") != -1) clientos = "NT" if (tv.indexOf("NT 5") != -1) clientos = "2K" if (tv.indexOf("XP") != -1) clientos = "XP" } else{ if (tv.indexOf("MAC") != -1) { clientos = "MA"; } else{ if (tv.indexOf("OS") != -1) clientos = "OS" } } // --> </script>



Alternately you could execute some code instead of setting "clientos" variable. Here is a simple example where you don't need to store the OS for later. It redirects the browser to one page if the OS is Windows, a different page for other systems.

<script type="text/javascript"> <!-- always comment code out for non supported browsers. var tv = navigator.appVersion.toUpperCase(); if (tv.indexOf("WIN")) { document.location.href = "windows.html" } else{ document.location.href = "not_windows.html" } // --> </script>



Anyway, I hope this helps those that want it.