How can I target only Internet Explorer 11 with JavaScript?

后端 未结 7 2346
一个人的身影
一个人的身影 2020-11-27 03:23

What\'s the least error-prone way to target just IE11 with JavaScript?

Note: This should really only be done for analytics or informing the user what browser they\'r

7条回答
  •  迷失自我
    2020-11-27 03:33

    This will set ie to the version of IE, or 0 if none. It'll work for 1 through 11, but may not detect future versions if Microsoft drops the Trident engine.

    var ie = 0;
    try { ie = navigator.userAgent.match( /(MSIE |Trident.*rv[ :])([0-9]+)/ )[ 2 ]; }
    catch(e){}
    

    You may also be interested in my related, more detailed answer here.

提交回复
热议问题