jQuery 如何使用jquery检测IE11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20089145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to detect IE11 using jquery
提问by therion
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 ?
我有代码 $.browser 来检测浏览器,并根据结果一些布局样式。但是现在有了 ie 11,$.browser 将提供 mozilla v.11。有什么修理建议吗?
回答by swt
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.
在正则表达式修复中编辑,摘自评论。截至 2014 年 2 月 17 日,此修复适用于当前版本的 IE11。
回答by user3253525
That last one was correct.
最后一句是对的。
Example:
例子:
To apply a body style for IE only for IE7 and above (including 10+11...)
仅对 IE7 及以上(包括 10+11...)应用 IE 的 body 样式
Copy/Paste this code inside the <head></head>
tag:
将此代码复制/粘贴到<head></head>
标签中:
<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>