how to detect IE11 using jquery [duplicate]

自古美人都是妖i 提交于 2019-12-03 12:53:47

问题


I have codes $.browser to detect the browser and upon the result some layout style is based. but now with ie 11, $.browser would give mozilla v.11. any suggestion to repair ?


回答1:


Try this:

var isIE11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
alert(isIE11);

EDIT:

Editted in a regex fix, taken from the comments. This fix works in the current version of IE11 as of 2/17/2014.




回答2:


That last one was correct.

Example:

To apply a body style for IE only for IE7 and above (including 10+11...)

Copy/Paste this code inside the <head></head> tag:

<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>//<![CDATA[ 
$(function(){
      if(navigator.userAgent.match(/Trident\/7\./)) {
          $('body').addClass('if-ie');
     }


});//]]>
</script>


来源:https://stackoverflow.com/questions/20089145/how-to-detect-ie11-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!