简体   繁体   中英

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?

Edit: I wonder if this would work: <!--[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?

For something to appear in 'other browsers' that don't support CCs, you need a downlevel-revealed conditional comment.

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

(this is slightly different to Microsoft's official syntax which is not valid HTML.)

“All browsers except IE8” is an unusual requirement, are you sure that's what you want? What about future versions of 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.

<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]也许?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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