Jump to content

Page navigation

Content

Valid downlevel-revealed conditional comment

We all know conditional comments in the form <!--[if cond]>…<![endif]--> that hide content from all browsers except IE/Win. Microsoft calls these downlevel-hidden conditional comment. The other form downlevel-revealed conditional comment is supposed to content from IE/Win, but not from other browsers. Unfortunately it does not validate.

But I think I found a way to make it work

I do not know, if this is something new. But I could not find anything similar on the net, only the fact that downlevel-revealed conditional comment should not be used, because they do not validate. I posted this on the comp.infosystems.www.authoring.html newsgroup, but without any response - it is either boring old news or ignored for another reason.

Internet Explorer has a pretty strange behaviour, when you nest downlevel-hidden and downlevel-revealed comments. In fact you can wrap the if and endif parts and a downlevel-revealed block seperatly in downlevel-hidden block:

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

Translate this into another programming language like C, PHP or Perl and you will see, why this kind of nesting make my heart scream:

if ( IE ) { if ( !IE ) { }
...
if ( IE ) { } }

Argh! The way IE parses such constructs of conditional comments seems ... strange. But it seems to work and it validates. Take a look at the example - if you find any browser that does not give the intended result, please drop me a note.

You are reading the (archived) weblog of Benjamin Niemann. This weblog has been closed, no new articles will be posted here.
If you can read german, you may have a look at my new weblog.

Navigation:

Archive:

Small print