开发者

How to comment out IE conditional comments?

开发者 https://www.devze.com 2022-12-25 20:50 出处:网络
I\'m just wondering if it\'s possible to comment out IE conditional comments themselves (for testing purposes)? The following开发者_开发知识库 does not work:

I'm just wondering if it's possible to comment out IE conditional comments themselves (for testing purposes)? The following开发者_开发知识库 does not work:

<!-- <!--[if IE 7]> some code <![endif]--> -->

Thanks in advance! flexx


No, it isn't possible.

SGML/HTML/XML/XHTML comments cannot be nested.


I think you can just insert something to make them invalid:

<!--\[if IE 7]> some code <!\[endif]-->


<!--[if IE 70]> some code <![endif]-->

:)


If I were you I'd use a template systems like Template Toolkit and then Just include or exclude the comment conditionally, based on some variable you could set at runtime.

Template Toolkit http://template-toolkit.org/


If you are sending that through a server such as .asp or aspx then of course you could comment that out server side.


You can't nest comments, but you can comment them out by adding an extra <!-- to the beginning. Your example from above changes from <!-- <!--[if IE 7]> some code <![endif]--> --> to <!-- <!--[if IE 7]> some code <![endif]-->. Just take out the extra --> and it should comment out that pesky conditional.

Tested successful in Firefox 3.5.2 and IE 7.0.5730.13CO

0

精彩评论

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