How can you detect the version of a browser using Javascript?


In this article, we are going to discuss how to detect the version of a browser using JavaScript.

These days, most browsers are JavaScript−enabled. But still, there are some browsers that don’t support JavaScript; or, some versions of some browsers don’t support certain features of JavaScript.

Therefore, in certain instances, there is a need to know the details of the client’s web browser so that the applications can deliver appropriate content.

Detecting the Version of a Browser

You can detect the details of the current browser using navigator.appName and navigator.appVersion properties.

To detect the version of the browser in the JavaScript we need to use navigator.appVersion or navigator.userAgent. The navigator.appVersion is a read-only property and it returns a string and represents the version information of the browser.

Example 1

In the following example, we are demonstrating the navigator.appversion to find the version and details of the browser.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Navigator</title>
</head>
<body>
   <h3>Navigator appVersion</h3>
   <p id="demo"></p>
   <button onclick="browserVersion()"> Return Browser varsion </button>
   <script>
      function browserVersion(){
        var v = "Version: " + navigator.appVersion;
        document.getElementById("demo").innerHTML = v;
      }
   </script>
</body>
</html>

Example 2

In the following example, we are demonstrating the navigator.userAgent to find the version and details of the browser.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Navigator</title>
</head>
<body>
<h3>Navigator userAgent</h3>
<p id="demo"></p>
<button onclick="browserVersion()"> Return Browser version </button>
   <script>
     function browserVersion() {
        //var v = "Version: " + navigator.appVersion;
        var v = "Version: " + navigator.userAgent;
        document.getElementById("demo").innerHTML = v;
     }
   </script>
</body>
</html>

Updated on: 19-Dec-2022

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements