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. This might be useful for web development, because some time developers need to write browser specific code.  Below I’m giving line of code that’s you can use simply copy and paste 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':
                // Get Intetnet Explorer Version
                version=useragent.substr(useragent.lastIndexOf('MSIE') +5,3);
            case 'Netscape':
                if (useragent.lastIndexOf('Chrome/') >0) {
                    // Get Chrome Version
                    version=useragent.substr(useragent.lastIndexOf('Chrome/') +7,10);
                else if (useragent.lastIndexOf('Firefox/') >0) {
                    // Get Firefox Version
                    version=useragent.substr(useragent.lastIndexOf('Firefox/') +8,5);
                else if (useragent.lastIndexOf('Safari/') >0) {
                    // Get Safari Version
                    version=useragent.substr(useragent.lastIndexOf('Safari/') +7,6);
                else {
                    // Display undifine browser name
                    alert('Undefine Browser');
            case 'Opera':
                version=useragent.substr(useragent.lastIndexOf('Opera/') +6,5);
                // Get Opera Version

Note:  For executing above JavaScript, Import following JavaScript file

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

I hope you enjoy this article and it helpful for you.

  Modified On Nov-30-2017 05:23:38 AM

Leave Comment