Tuesday, April 9, 2013

Conditional Comments

This is a technique that will make your code technically invalid, but it can be fun.


<![if !IE]>
<a href="http://www.hu.mtu.edu/~wkzander/hu3650/sp12/?q=node/18#requirement" id="widthlimiting" title="Click to see the requirements for this class project"><img class="scaling" src="firstworld.png" alt="I dont't get to relax on a friday night because I had to turn in a website for class."></a>
<![endif]>
<!--[if IE]>
<a href="http://www.google.com/chrome" id="widthlimiting" title="Click to go get a real browser"><img class="scaling" src="zoidberg.png" alt="Your browser is bad and you should feel bad."></a>
<![endif]-->

The <![if !IE]> and <![endif]> tags are read as invalid, and just get passed over by every browser that isn't internet explorer. IE ignores what's in between them and gets triggered to look for the next set of comment tags, <!--[if IE]> and <![endif]--> (which do validate), then treats them as though the contents aren't a comment. This is a process called conditional commenting. It's a simple, if invalid, way of making things appear differently in IE.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.