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.
- Using your server sided script
- Using JavaScript or any other browser sided script
- Conditional Comments
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.
Reference:
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.
0 comments:
Post a Comment