Jquery fail to detect IE 11

前端 未结 4 676
长情又很酷
长情又很酷 2020-11-29 07:18

Just stumbled upon an issue. When trying to detect IE 11 (the beta version currently on air) using Jquery, the result is \'firefox\'. The same code detect IE 10. I need to k

相关标签:
4条回答
  • 2020-11-29 07:45

    It's for compatibility reasons. Client code often performs browser detection instead of feature detection (which is a poor practice). So in an effort to make sure that clients properly use all of IE 11's capabilities Microsoft has made it so that IE 11 will report that it's Mozilla compatible.

    So instead of doing browser detection, do feature detection. See Browser detection versus feature detection. There's some great libraries for that, with Modernizr probably being the most well known (and Microsoft ships it as part of the ASP.NET templates in Visual Studio).

    See MSDN blog about IE 11 User Agent Strings.

    0 讨论(0)
  • 2020-11-29 08:02

    jQuery.browser is long deprecated and has been removed, you should use $.support or a better tool like Modernizr

    0 讨论(0)
  • 2020-11-29 08:04

    The final solution:

    if (!!navigator.userAgent.match(/Trident\/7\./))
      return "ie";  
    

    We can only hope that the release version will act the same.

    0 讨论(0)
  • 2020-11-29 08:06

    The purpose of jQuery Migrate is to allow old badly-written code to run, not to encourage writing new badly-written code. Since that old badly-written code was created long before IE11 was released, it doesn't know about IE11 anyway and will probably misbehave regardless. The jQuery Migrate plugin won't be changed to detect IE11. If you are writing new code, don't use browser detection. Instead, use feature detection.

    0 讨论(0)
提交回复
热议问题