Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional comment for 'Except IE8'?

I'm using <!--[if IE 8]><![endif]--> for targeting IE8, but there's some JS that I want to load for all browsers EXCEPT IE8, what conditional comment should I use?

Edit: I wonder if this would work: <!--[if lte IE 8]><![endif]-->

Thanks

like image 845
eozzy Avatar asked Nov 07 '09 05:11

eozzy


People also ask

What is conditional comment in HTML?

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 are not supported in Internet Explorer 10 and 11.

What is IE condition?

Conditional comments are a simple Internet-Explorer-only feature that Microsoft added to IE5 Windows and later. (Mac IE doesn't support them.) They provide an easy way to detect that the visitor is using an IE browser (and which version they're using). You can then serve IE users different blocks of HTML as required.

What are conditional comments and when are they necessary?

Conditional comments, which are nothing more than simple HTML comments that IE (up to version 9) happens to take a peep at, are used to throw a chunk of HTML at these browsers and only these browsers. Other well behaved, top-of-the-class browsers will simply see them as unremarkable comments and move along.

What is if IE in HTML?

--[if IE]> syntax, resolves the if and parses the content of the conditional comment as if it were normal page content. Since conditional comments use the HTML comment structure, they can only be included in HTML files, and not in CSS files.


1 Answers

there's some JS that I want to load for all browsers EXCEPT IE8, what conditional comment should I use?

For something to appear in ‘other browsers’ that don't support CCs, you need a downlevel-revealed conditional comment.

<!--[if !IE 8]><!-->
    ....
<!--<![endif]-->

(this is slightly different to Microsoft's official syntax which is not valid HTML.)

“All browsers except IE8” is an unusual requirement, are you sure that's what you want? What about future versions of IE?

like image 69
bobince Avatar answered Oct 14 '22 05:10

bobince