开发者

IE9 Broke Conditional Comments for Javascript?

Hey all, doing some repairs on systems after the IE9 release earlier this month. Just wanted to know if anyone else has experienced the same problems with conditional comments and IE9 as I have and if there are any better workarounds for my problem.

Conditional comments are pretty well known to work consistently as a workaround for the IE browsers. IE9 seems to break this. I was testing an IE9-specific script (specifically document.createElement("<input name='something'>"); broke in IE9 but thats a different issue), and I needed to make a workaround for IE 6 & 7. So I did this:

    <!--[if IE 6]>
    <script type="text/javascript">
        var ie6 = true;
    </script>
    <![endif]-->
    <!--[if IE 7]>
    <script type="text/javascript">
        var ie7 = true;
    </script>
    <![endif]-->

Turns out in IE9, both ie6 and ie7 are true. WTF.

My workaround was to change it to the conditional comment below reverse the logic and just do if(!ie9plus).

    <!--[if gte IE 9]&g开发者_JS百科t;
    <script type="text/javascript">
        var ie9plus = true;
    </script>
    <![endif]-->

Is there a better workaround? Should we be yelling and screaming at the IE development team for breaking such an important aspect of web debugging?

EDIT: Upon further testing, it seems it was an encoding problem. Somehow the file was encoded wrong and it broke the conditional comment. When I changed the comment to the IE9 one I fixed the file encoding too. IE9 does in fact properly support conditional comments. Sorry about the FUD.


The IE blog says they still work. They are, however, tied to the rendering mode and is either 7 or 9 (the former in compat view).

The IE team discourages the use of conditional comments, though, as they cater for browsers, instead of detecting features. However, that's probably mostly a consideration for Javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜