9

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

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

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

4

2 回答 2

19

对 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,但我认为在一个地方显示完整的检测代码会很有帮助。

于 2013-06-12T21:53:48.553 回答
3
    <!-- IE10 -->
    <script>
    if(navigator.userAgent.match(/MSIE 10/)){

        var headID = document.getElementsByTagName("head")[0];   
        var newLink = document.createElement('link');

        newLink.rel = 'stylesheet';
        newLink.type = 'text/css';
        newLink.href = 'css/ie10.css';

        headID.appendChild(newLink);
    } else {
       /* do something for other versions */
    }
    </script>
于 2013-06-14T20:28:58.680 回答