jquery - 检测 <= IE10 的最佳方法

标签 jquery css internet-explorer detection

检测 IE 的最新方法是什么?

  • 条件注释不适用于 IE9, IE10
  • modernizr 特征检测在这里没有帮助,因为原因是外部的(我想嵌入的 mapbox map 中的 IE 错误)
  • jQuery + 迁移插件:如果有帮助,基本步骤是什么?

是的,我对此很陌生。干杯!

最佳答案

为 IE6-9 使用条件注释,为 IE10 使用一些自定义函数。例如: HTML:

<!--[if lt IE 7 ]> <html class="ie6 ie"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7 ie"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8 ie"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9 ie"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

JS:

if ($('html').hasClass('ie') || (Function('/*@cc_on return document.documentMode===10@*/')())){
    isIE = true;
}else{
    isIE = false;
}

或者你可以只使用:

if (Function('/*@cc_on return document.documentMode===10@*/')()){
    document.documentElement.className+=' ie';
}
// Then..
if($('html').hasClass('ie')){...} // to check for IE10 and below.

其他答案侧重于专门检测 IE10,但我认为在一个地方显示完整的检测代码会有所帮助。

关于jquery - 检测 <= IE10 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17075828/

相关文章:

javascript - 为什么我不能在我的网页上滚动?

css - 居中对齐 <li> 标签内的隐藏 div 用于菜单下拉

javascript - jQuery - 如何打印类名

javascript - 图像渲染 DOM 等价物

jquery - 如何在 IE 中使用 javascript 而在所有其他浏览器中使用 css?

Firefox 上的 jQuery 动画缩放

javascript - 为什么我的 jquery animate() 回调会导致溢出?递归

javascript - 从页面上的许多其他表单中选择一个表单,并将输入的数据保存到数据库中

javascript - IE6 中的 JSON 对象 - 如何?

html - 输入字段设置为 'Value=' 而不是 'value='