Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write conditional comment for non IE browsers?

I don't want to use a couple of javascript plugins for IE 6/7. But I want to use them for all other browsers.

How can I do it? Is there any way I can do it?

like image 202
shin Avatar asked Jul 02 '09 10:07

shin


People also ask

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.

How do you use conditional comments in HTML?

Conditional comments are conditional statements to hide or provide HTML source code from Internet Explorer. 2. There are two types of conditional comments - downlevel-hidden - which is used to hide HTML source and downlevel-revealed which is used to reveal HTML source code in Internet Explorer.

How do I get CSS only for Internet Explorer?

#2 CSS Rules Specific to Explorer (IE CSS hacks) IE8 or below: to write CSS rules specificially to IE8 or below, add a backslash and 9 ( \9 ) at the end before the semicolon. IE7 or below: add an asterisk ( * ) before the CSS property. IE6: add an underscore ( _ ) before the property.

What is IE condition?

Internet Explorer Conditional comments are conditional statements used only by Microsoft Internet Explorer in HTML source file. It gets frustrating when different versions of Internet Explorer displays web pages differently due to the browser problems.


2 Answers

From the Wikipedia article on conditional comments (modified to fit your version requirements):

<!--[if gt IE 7]><!-->
<p>This code displays on non-IE browsers and on IE 8 or higher.</p>
<!--<![endif]-->

The weird markup in the first line serves to make the markup standards compliant.

like image 95
Jørn Schou-Rode Avatar answered Oct 22 '22 00:10

Jørn Schou-Rode


Your question would be better phrased as "Using conditional comments to exclude content from IE browsers" ;-)

Although CCs are most often used to provide additional content for IE, there is a variant that allows you to prevent IE from seeing content. With their usual arrogance, MS chose to call this "downlevel-revealed conditional comments" (because all other browsers are worse than IE in their world).

Something like

<![if !IE]><p>You are not using Internet Explorer.</p><![endif]>

should be all you need.

Note that describing this as a "Conditional Comment" is another example of MS's strange use of words to mean exactly what they choose them to mean rather than what everybody else means: the above works because it isn't actually a comment, so all browsers other than IE just assume you made a hideous mistake in your HTML and carry on parsing the content within.

This also means it will probably fail badly in XHTML served with the application/xhtml+xml content type, but that's another story.

like image 20
NickFitz Avatar answered Oct 21 '22 22:10

NickFitz