2

I'm trying to write a simple script that will display the current browser name, version, and the operating system. Here's but don't think I'm on the right path. Also how can I use parseInt() function to print just the version number?

<!DOCTYPE html>
<html>
<head>
    <title>Window Open Example 2</title>
</head>
<body>
     <script type="text/javascript">
        document.write(navigator.appVersion);
     </script>
</body>
</html>
4
  • 1
    possible duplicate of Detect version of browser Commented Aug 20, 2014 at 8:00
  • 1
    Standards do not support browser sniffing instead they support determining if the browser has a feature. What this means is that whatever you do today to determine the browser may not work for the next version of browser. Commented Aug 20, 2014 at 8:01
  • 1
    Refer http://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript Commented Aug 20, 2014 at 8:01
  • Feature detection is a more modern approach to this. Commented Aug 20, 2014 at 8:06

2 Answers 2

2

You should use parseFloat in case of Version number like "5.01"

document.write(parseFloat(navigator.appVersion).toFixed(1));

toFixed() tells how many dezimal places should be visible.

Sign up to request clarification or add additional context in comments.

Comments

0

for get browser name

<script>document.getElementById("demo").innerHTML
="Name is " + navigator.appName +". ode name is " + navigator.appCodeName;

for version

document.getElementById("demo").innerHTML = navigator.userAgent;

for 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);

for parseINT

      document.getElementById("demo").innerHTML =
      parseInt(navigator.appVersion, 10);

3 Comments

-1 navigator.appName does not return the correct browser name since all browsers except IE will probably return Netscape instead. userAgent returns versions for every part of the browser.
yes.but reason for that click here
I know why browsers are returning "Netscape". What basically I'm saying is that your answer is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.