How to detect IE 11 with javascript in Asp.net

后端 未结 10 1906
暖寄归人
暖寄归人 2020-12-01 05:04

Hello I want to detect the Browser , IE 8 or more will be appropriate for me. For this i used following code but it fails for IE 11 . For other its detecting properly.

10条回答
  •  旧巷少年郎
    2020-12-01 05:20

    As already stated - dont do browser detection, rather do feature detection. However as I see your script is an older version of a script the circulates around here. This is the updated version that detects IE 11 aswel:

    function getInternetExplorerVersion()
                                {
                                    var rv = -1;
                                    if (navigator.appName == 'Microsoft Internet Explorer')
                                    {
                                        var ua = navigator.userAgent;
                                        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
                                        if (re.exec(ua) != null)
                                            rv = parseFloat( RegExp.$1 );
                                    }
                                    else if (navigator.appName == 'Netscape')
                                    {
                                        var ua = navigator.userAgent;
                                        var re  = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
                                        if (re.exec(ua) != null)
                                            rv = parseFloat( RegExp.$1 );
                                    }
                                    return rv;
                                }
    

提交回复
热议问题