---
title: "Detect Browser and Version using JavaScript"  
description: "In this article I’m trying to explain, how to get browser name and its version (Chrome, Firefox, Internet Explorer, Opera and Safari) using JavaScript"  
author: "AVADHESH PATEL"  
published: 2013-04-23  
updated: 2017-11-30  
canonical: https://www.mindstick.com/articles/1265/detect-browser-and-version-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Detect Browser and Version using JavaScript

In this article I’m trying to [explain](https://www.mindstick.com/forum/159699/what-is-a-compilation-error-in-dot-net-core-explain-with-an-example), how to get [browser](https://www.mindstick.com/articles/323165/top-10-fastest-internet-browsers-in-the-world) name and its [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) (Chrome, [Firefox](https://answers.mindstick.com/qa/95593/how-do-i-manage-firefox), [Internet](https://yourviews.mindstick.com/view/81617/now-it-is-time-to-say-goodbye-to-internet-explorer) Explorer, Opera and Safari) using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript). This might be useful for [web development](https://www.mindstick.com/services/web-development), because some time [developers](https://yourviews.mindstick.com/view/88480/why-developers-combine-multiple-ai-tools-instead-of-one) need to write browser specific code. Below I’m giving line of code that’s you can use simply [copy and paste](https://answers.mindstick.com/qa/95127/how-do-you-copy-and-paste-the-contents-of-a-pdf) in your web project.

```
<script type="text/javascript">    $(function () {        // Get Browser Name        var browser=navigator.appName;        // Get All Navigator Browser Name and Version        var b_version=navigator.appVersion;        // Get Navigator Browser Version        var version=parseFloat(b_version);        // Browser Navigator Name        var useragent=navigator.userAgent;        switch (browser) {            case 'Microsoft Internet Explorer':                browser="MSIE";                // Get Intetnet Explorer Version                version=useragent.substr(useragent.lastIndexOf('MSIE') +5,3);                alert(version);                break;            case 'Netscape':                if (useragent.lastIndexOf('Chrome/') >0) {                    browser="Chrome";                    // Get Chrome Version                    version=useragent.substr(useragent.lastIndexOf('Chrome/') +7,10);                    alert(version);                }                else if (useragent.lastIndexOf('Firefox/') >0) {                    browser="Firefox";                    // Get Firefox Version                    version=useragent.substr(useragent.lastIndexOf('Firefox/') +8,5);                    alert(version);                }                else if (useragent.lastIndexOf('Safari/') >0) {                    browser="Safari";                    // Get Safari Version                    version=useragent.substr(useragent.lastIndexOf('Safari/') +7,6);                    alert(version);                }                else {                    // Display undifine browser name                    alert('Undefine Browser');                }                break;            case 'Opera':                version=useragent.substr(useragent.lastIndexOf('Opera/') +6,5);                // Get Opera Version                alert(version);                break;        }    });    </script>
```

Note: For executing above JavaScript, Import following JavaScript file\

```
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> OR <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> OR Any “jquery.js” updated library. 
```

I hope you enjoy this article and it helpful for you.

---

Original Source: https://www.mindstick.com/articles/1265/detect-browser-and-version-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
