Forum Moderators: open

Message Too Old, No Replies

HTML Conditional Comments for IE

show or hide code to Explorer by version number

         

tedster

8:54 am on Feb 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks to ranjan for bringing this up in a thread about using CSS to simulate frames [webmasterworld.com] over at the CSS Forum.

The idea is that with a very simple syntax, you can do a kind of inline browser sniff for versions of IE and feed them code that other browsers won't see.

The basic code looks like this:

<!--[if IE 6]>
<p>Any HTML you want for IE6 and up goes in here</p>
<![endif]-->

You can use any version number from IE 5 up, including the decimal version number if you need it. Some pretty powerful effects and/or workarounds become possible by bringing in a linked stylesheet just for IE. It can also be handy for dealing with changes in the DOM.

Also there is a related syntax that only REVEALS the code to browsers below a certain version:

<![if!IE 5]>
<p>Please upgrade to Internet Explorer version 5.</p>
<![endif]>

Microsoft Developer Reference [msdn.microsoft.com]

Birdman

12:21 pm on Feb 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you for that link, Tedster. I have been neglecting the older browsers for some time and need to get my pages more compatible to them. That tip may help some.

gsx

2:49 pm on Feb 5, 2003 (gmt 0)

10+ Year Member



But remember that because of the <!-- and --> in the first example, spiders are likely not to index the contents between.

Also, <!--[if IE]>...<![endif]--> can show code to any version of IE but not other browsers.