How do I detect IE10 using javascript?

后端 未结 6 1950
离开以前
离开以前 2020-12-14 04:15

As many already posted in other questions (also in jQuery documentation), the old jQuery.browser.version is deprecated and works only in jquery1.3.

Do y

6条回答
  •  渐次进展
    2020-12-14 04:58

    In general it's a bad idea to check for browser version, it's considered a better practice to check for browser features. But if you're sure what you're doing:

    function getIEVersion(){
        var agent = navigator.userAgent;
        var reg = /MSIE\s?(\d+)(?:\.(\d+))?/i;
        var matches = agent.match(reg);
        if (matches != null) {
            return { major: matches[1], minor: matches[2] };
        }
        return { major: "-1", minor: "-1" };
    }
    
    var ie_version =  getIEVersion();
    var is_ie10 = ie_version.major == 10;
    

    We have the following code in production, so it works and well-tested.

    And yes, we did have a need to detect IE10, not just a particular feature that exists in IE10 but not in earlier versions.

提交回复
热议问题