I was pondering this question last night while debugging some things in IE7, when I typed in <!--[if IE7]>...
it occured to me that I've seen <!--[if !IE]>
.
Now what get me is that as far as I understand it, only IE recognises these conditional comments, so to to say if NOT IE
makes no sense, does IE see this and say "Iam IE, so this doesn't apply to me?" or are people getting confused with which browsers can recognise it?
So my question is.
Where would you use <!--[if !IE]>
and what is its purpose?
To detect whether the current browser is Internet Explorer, you can make use of the navigator. userAgent property. The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.
Conditional comments are conditional statements interpreted by Microsoft Internet Explorer versions 5 through 9 in HTML source code. They can be used to provide and hide code to and from these versions of Internet Explorer.
Conditional comments use a special syntax—HTML markup wrapped in a conditional statement—and are placed within an HTML comment. If the statement evaluates to true , the enclosed HTML is revealed within the HTML document. If the statement evaluates to false, the enclosed HTML remains hidden.
You can use it with a special synax:
<!--[if !(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
This means that IE ignores what is in between, but other browsers treat the conditional comments as closed comments and interpret what's in between.
I would say it would be if you wanted to run a script that works in every browser other than IE, as IE would not run it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With