You're obviously not using IE5, as you're able to see this section of code. If you haven't already seen this page in IE5, then you don't know what you're missing (well, it's a section rather like this one, actually). Try copying the URL of this page from the address bar, then pasting it into the address bar of IE5. You'll see most of this page in the other browser, but not this bit - you'll see a different section here instead!


Conditional comments in IE5 are great news, as they let you fence off entire sections of HTML and script code, either for viewing only by IE5, or for viewing only by browsers other than IE5.

Until now it's been amazingly hard to protect sections of browser-specific HTML code from being processed by incompatible browsers - basically you had to resort to pumping out the required HTML from a script, using the document.write() method conditioned by a test on the browser type (which is every bit as complex as it sounds).

That's still the case if you're distinguishing between, say, IE4 and Navigator, but at least you can easily distinguish between IE5 and all other browsers (including IE4), using conditional comments.

To make some page content viewable only by IE5, enclose it in an <!--[if IE 5]>...<![endif]--> container. To make some page content viewable only by browsers other than IE5 (including IE4),  enclose it in an <![if ! IE 5]>... <![endif]> container.

Here's the source code for this page:

<html>
<head></head>
<body>

<!--[if IE 5]>
<p><img border="0" src="wwie5lgo.gif" align="left"><b>You're obviously using
IE5...

<![endif]-->

<![if ! IE 5]>
<p><img border="0" src="oldb.gif" align="left"><b>You're obviously
<u>not</u>using IE5...

<![endif]>

<p>
Conditional comments in IE5 are great news....

</body>
</html>


Back to menu