• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Conditional Comments

It’s just a fact of life that not all browsers render code the same way. Even browsers of the same brand but varying versions can cause issues. That’s one reason why there are so many different “browser sniffer” scripts available on the web. After the browser is determined, rendering variations may be accounted for using JavaScript or the users may be redirected to a page specifically for their browser.If all you’re interested in is changing something specifically for Internet Explorer, you’ll find that conditional comments are a much simpler way to go. Conditional comments are only recognized in Internet Explorer 4 and above, whereas non-Internet Explorer browsers treat them as regular HTML comments that are not seen by the browser. You can put virtually anything you want between the opening and ending conditional comment syntax. The syntax is simple; if less than Internet Explorer, do all this stuff until you get to the endif syntax.

<!--[ if lt IE 6]>
Please upgrade to Internet Explorer 6.
<![ endif]-->

As you may have guessed, you can check for other browser versions, and use operators such as gt for greater than, gte for greater than or equal to, and several other operators. I’d better just show you where to find the rest of the operators; all you need to know about conditional comments, you can find at the MSDN site: http://www.dwkillertips.com/go/21.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint