Wednesday, July 21, 2004

Hiding HTML from IE with Conditional Comments

After having failed to find the incantation before, a slightly different bit of Googling turned up this trick, that saves the needless <span> in IE that I had in the previous entry :



where I've folded this at necessary whitespace. The <acronym/> is IE only, the <abbr/> is non-IE (or back version IE, which won't know what to do with it...).

1 comment :

Anonymous said...

Very nice, light-weight solution. I was about to implement some browser sniffing script but you have provided just what I was looking for.

When I finally understood how it was working, I think I found a few characters that are unneeded:


<!--[if IE]>
HTML you want only MSIE to see
<![endif]-->
<!--[if !IE]>-->
HTML you want all other browser to see
<!--<![endif]-->

(the limitations of the html allowed in comments here is making it difficult to convey this the ampersanded "greater than" should be replaced by the actual symbol in your html)


My first application of this will be a little "position:fixed;" link on my long pages so that readers can jump to the top of the page. IE users...they'll have to wait for MSIE 7.0.

Thanks again!