Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would <!--[if !IE]> be used?

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?

like image 700
Kyle Avatar asked Feb 11 '11 09:02

Kyle


People also ask

How can I tell if Internet Explorer is being used?

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.

Which is the only browser that supports conditional comments?

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.

How do you use conditional comments in HTML?

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.


2 Answers

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.

like image 146
Horia Dragomir Avatar answered Sep 26 '22 16:09

Horia Dragomir


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...

like image 31
Paddy Avatar answered Sep 25 '22 16:09

Paddy