tags:

views:

83

answers:

3

I want to apply javascript and CSS to all browser but not to IE6 is it possible?

for example I have a javascript abc.js

I want to use this javascript in all browser IE7, IE8, IE9, Firefox, Safari, Chrome.

But i don't want to use this javascript in IE6.

+7  A: 

This should be possible using a combination of conditional comments.

You'd have to specify things twice but otherwise, this should work:

<!--[if gt IE 6]>
   For Internet Explorer > 6
<![endif]-->

<![if !IE]>
 For all other browsers 
<![endif]>
Pekka
That won't be parsed by non-IE browsers.
BoltClock
@BoltClock yup, you're right. Added something to fix that.
Pekka
@pekka - both are not working
metal-gear-solid
@metal where are you testing this, in IETester?
Pekka
@Pekka - in Firefox and IE 6 in Microsoft VPC
metal-gear-solid
@Pekka - for example I have a js called `rotate.js` and i only want to use rotate effect in all latest browsers except IE6. I used your solution but FF not rendering the js.
metal-gear-solid
+1  A: 

You can use conditional comments to do stuff by excluding IE 6 or lower.

<![if gt IE 6]>
Markup used by IE 7, 8 and above, and all other browsers ignoring these proprietary tags...
<![endif]>

That's the "Downlevel-revealed Conditional Comments".

PhiLho
+1 this is more elegant than mine. However, there is the (very small) possibility that future browsers of other families start supporting those tags, in which case this would be limited to the IE family.
Pekka
+2  A: 

Andy Clarke has the answer in his Universal IE6 CSS project. I recommend the article on his 'For a beautiful web' site, as he has a specific approach to just this problem - which may or may not be for the same reasons you wish to carry out this ie6 only favouritism!

From his Universal IE6 CSS code:

To hide all your other stylesheets from Internet Explorer 6, wrap them inside this Conditional Comment.

<!--[if ! lte IE 6]><!-->
/* Stylesheets for browsers other than Internet Explorer 6 */
<!--<![endif]-->

Then add the Universal Internet Explorer 6 stylesheet.

<!--[if lte IE 6]>
<link rel="stylesheet" href="http://universal-ie6-css.googlecode.com/files/ie6.1.1.css" media="screen, projection">
<![endif]--> 

See below for the full article, and the links within it for the full code: http://forabeautifulweb.com/blog/about/universal_internet_explorer_6_css

crunch
thanks it's working for me
metal-gear-solid
not working i was wrong
metal-gear-solid