mo.notono.us

Wednesday, February 25, 2009

HTML: Conditional Else Comment

IE browsers support Conditional Comments, but the syntax only supports IF statements – there is no ELSE.

Stu Nicholls and the JavaScript Kit to the rescue;  the following simulates an else statement:

<html>
 <head><title>Choose a browser...</title></head>
 <body>
  <p>You chose
  <![if ! IE]>
  wisely
  <![endif]><!--[if IE]>
  poorly
  <![endif]-->
  ...</p>
 </body>
</html>

Copy to a text file, save as html and run in IE and Firefox/Chrome/Safari/Opera…

Labels: , ,

2 Comments:

Post a Comment

<< Home