Skip to content Skip to sidebar Skip to footer

Why Using Window.navigator.useragent To Retrieve The Browser Explorer 11 Is Recognized As Mozilla? How Retrieve The User Angent And Version?

I am pretty new in JavaScript and JQuery and I am going crazy trying to implement a simple script that detect if the browser is Internet Explorer and its version. So I am doing som

Solution 1:

According to Microsoft, IE11's user agent string is specially designed to trick UA parsers into recognizing it as something else. Source: http://blogs.msdn.com/b/ieinternals/archive/2013/09/21/internet-explorer-11-user-agent-string-ua-string-sniffing-compatibility-with-gecko-webkit.aspx

I will repeat this even if it is mentioned in the article above. If you want to do UA sniffing, please think twice. Feature detection is the recommended way to deal with browser compatibility. See the article for more on this.

Solution 2:

IE 11 broke all client-side check scripts with its release. As you said, it now reports as "Mozilla" and no longer reports the MSIE. As far as what I remember, the decision they took was to do this because IE11 is supposed to be based more on the Gecko engine as opposed to Mozilla. To illustrate this, Microsoft decided to change the User-Agent string to something different. The best way I know to test for IE11 is to check for "Trident/7.0" which is supposed to be informed by all IE11 browsers.

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

Anyway, as many will recommend, it is better to check for functionalities rather than relying on browser checking.

Solution 3:

Please try to below code.

var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");
    var rv = -1;

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer, return version number
    {               

        if (isNaN(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))))) {
            //For IE 11 >if (navigator.appName == 'Netscape') {
                var ua = navigator.userAgent;
                var re = newRegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
                if (re.exec(ua) != null) {
                    rv = parseFloat(RegExp.$1);
                    alert(rv);
                }
            }
            else {
                alert('otherbrowser');
            }
        }
        else {
            //For < IE11alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
        }
        returnfalse;
    }}

Post a Comment for "Why Using Window.navigator.useragent To Retrieve The Browser Explorer 11 Is Recognized As Mozilla? How Retrieve The User Angent And Version?"