开发者

Compatibility of conditional HTML-Comments?

<![if lt IE 7]> code to be executed by internet explorer versions prior to 7 <![endif]>

its great and seems to work fine. but the only technical specification i can find about is at microsoft and it clearly states that its only interpreted by internet explorer.

so usual comments look like this <!-- comment --> .

my question:

could some browser end up with not interpreting <![if lt IE 7]> as a comment but as code and just displaying it plain?

开发者_Go百科

i know that this qustion may not be well formed but i don't know how to rephrase it to be more precise. please feel free to edit and comment if its unclear so i can modify.


It's not

<![if lt IE 7]>

it's

<!--[if lt IE 7]>

So no, other browsers that correctly parse HTML comments in the first place will always see the <!-- that opens the comment block.


Conditional comments are actually preceded by <!-- which makes them HTML comments...

<!--[if IE 7]>
Special instructions for IE 7 here
<![endif]-->

So if the browser supports comments then it won't display it. And I would guestimate that any browser made since around 2000 has supported HTML comments.


reading a bit deeper at microsoft:

When comparing this type of comment to the basic HTML Comment, notice that there are no hyphens ("--") immediately after the opening "" of the comment block; therefore, the comment delimiters are treated as unrecognized HTML. Because the browser does not recognize the downlevel-revealed conditional comment, it does nothing with it.

and

The downlevel-hidden conditional comment contains hyphens ("--") in the opening and closing tag, similar to the basic HTML Comment. The condition appears in the opening portion of the tag, and [endif] is placed prior to the closing portion of the tag. The content is placed inside the comment tags.

Because the first four characters and the last three characters of the comment are identical to a basic HTML Comment element, downlevel browsers ignore the HTML content inside the comment block. Since content is effectively hidden from browsers that do not support conditional comments, this type of conditional comment is called downlevel-hidden.

If the result of the conditional expression is true, the content inside the comment block is parsed and rendered by Internet Explorer 5 and later versions. This behavior makes the downlevel-hidden conditional comment particularly useful for content that has been specifically designed for Internet Explorer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜