I moved to Now I am blogging there, so please visit and keep me reading. love, Debiprasad

Ask questions related to online shopping in India

Where to buy online in India?

Use Conditional Comments for Internet Explorer Specific Code

If you want to display some content in any web page, specific for internet explorer or other than it, you can do it at least 3 ways.

  1. Using your server sided script
  2. Using JavaScript or any other browser sided script
  3. Conditional Comments
Now I am going to discuss about Conditional Comments. Conditional comment is some simple html code, if the condition satisfies, then the code between the start point and end point of the conditionals comments displays in the browser else treated as comment.

The following example shows the contents inside the conditional comments if the browser is Internet Explorer. For other browsers it will be treated as comment only.

If you want to run some code in the browsers other than Internet Explorer, the follow the following syntax.

Note: Here there is no -- before ! symbol at start of the tag and -- in end tag. This is called as Conditional comments revealed, which will be parsed by other browsers, but will be evaluated by the IE. If the condition satisfies, then IE will treat it as comments, else parse the code in between.

Now if you want to run some code in version specific Internet Explorer, then follow the syntax bellow.

Why to use conditional comments to detect browser?
It has two benefits. First one is it doesn't require server sided scripting, static websites can use it effectively. Second one is, you also don't need any client sided scripting.

MSDN - Detecting Internet Explorer More Effectively

To learn more about conditional comments please read: MSDN - About Conditional Comments

And if you are using Internet Explorer, please download Mozilla Firefox 3 to experience the best browsing ever. Firefox 3

Use Conditional Comments for Internet Explorer Specific CodeSocialTwist Tell-a-Friend TwitThis Reading: Use Conditional Comments for Internet Explorer Specific CodePost Link to Twitter


My Shared Items in Google Reader

My Blogroll


Want to see/show anything here? Contact me :)