简体   繁体   English

“IE8除外”的条件评论?

[英]Conditional comment for 'Except IE8'?

I'm using <!--[if IE 8]><![endif]--> for targeting IE8, but there's some JS that I want to load for all browsers EXCEPT IE8, what conditional comment should I use? 我正在使用<!--[if IE 8]><![endif]-->来定位IE8,但是我想为所有浏览器加载一些JS,除了IE8,我应该使用什么条件注释?

Edit: I wonder if this would work: <!--[if lte IE 8]><![endif]--> 编辑:我想知道这是否可行: <!--[if lte IE 8]><![endif]-->

Thanks 谢谢

there's some JS that I want to load for all browsers EXCEPT IE8, what conditional comment should I use? 我想为所有浏览器加载一些JS,除了IE8,我应该使用什么条件评论?

For something to appear in 'other browsers' that don't support CCs, you need a downlevel-revealed conditional comment. 对于不支持CC的“其他浏览器”中显示的内容,您需要一个下层显示的条件注释。

<!--[if !IE 8]><!-->
    ....
<!--<![endif]-->

(this is slightly different to Microsoft's official syntax which is not valid HTML.) (这与Microsoft的官方语法略有不同,后者不是有效的HTML。)

“All browsers except IE8” is an unusual requirement, are you sure that's what you want? “除了IE8之外的所有浏览器”都是一个不寻常的要求,你确定这是你想要的吗? What about future versions of IE? IE的未来版本怎么样?

I can think of a trick. 我可以想到一个技巧。 Set a variable inside the IE conditional tag and include your JS code if that variable isn't set. 在IE条件标记内设置变量,如果未设置该变量,则包含JS代码。

<script>
    var ie8 = false;
</script>

<!--[if IE 8]>
    <script>
        ie8 = true;
    </script>
<![endif]-->

<script>
    if (ie8 == false) {
        // any code here will not be executed by IE 8
        alert("Not IE 8!");
    }
</script>

尝试否定, [if !IE 8]也许?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM