views:

324

answers:

4

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?

+12  A: 

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.

Jørn Schou-Rode
+2  A: 

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.

NickFitz
This targets anything else than IE, but what about IE > 7? Also, the markup isn't valid HTML, and thus the behavior in any non-IE browser is unspecified.
Jørn Schou-Rode
The condition can be <![if gt IE 7]> for IE 8 and up. As for the invalid markup and unspecified consequences: what else do you expect from Microsoft? ;-)
NickFitz
A: 

There's a pretty good resource for such things at: http://www.javascriptkit.com/javatutors/conditionalcompile.shtml

This in conjunction with the @_jscript_version variable should help you achieve the desired result. (You'll have to Google "Version Information (Windows Scripting - JScript)" for the JScript -> IE version lookup as I'm only allowed to embed one link as a new user.) :-(

middaparka
A: 

You see, anonymous commenters are the actual assholes of the internet. And, your blog must be mildly interesting or successful if you are having to endure the wrath of anonymous commenters, because the thing they hate the most is when someone might actually, you know, feel good about themselves.

cheap nfl jerseys