2

Possible Duplicate:
How to find the operating system version using JavaScript

how i can detect that my visitor using which os and os version in javascrtip . for example windows vista or seven or Xp and linux too .

Community
  • 1
  • 1
A.B.Developer
  • 5,599
  • 9
  • 68
  • 140

3 Answers3

14

To detect the operating system on the client machine, your script should analyze the navigator.appVersion string. Below is a simple example of a script that sets the variable OSName to reflect the actual client OS.

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

On your system, this script yields the following result: Your OS: Windows

(To get more detailed OS information, your script should perform a more sophisticated analysis of the navigator.appVersion string, but the idea would be the same.)

Harold Sota
  • 7,061
  • 12
  • 53
  • 82
1

navigator.platform will give you the current platform they're using, just as navigator.userAgent will give you the whole browser string.

Marcus Frödin
  • 11,134
  • 2
  • 23
  • 16
0

Output of navigator.appVersion on Firefox/WinXP.

5.0 (Windows; en-US)

Output of navigator.userAgent on Firefox/WinXP.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8

Output of navigator.platform

Win32
Robby Pond
  • 70,876
  • 16
  • 121
  • 117