I have a fancy script that is nice, but not essential and surprise surprise, doesn't play nice with IE. How do I 'ment it out' for IE?
I know I can use the following to include statements for IE, but how do I exclude them?
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
I have a fancy script that is nice, but not essential and surprise surprise, doesn't play nice with IE. How do I 'ment it out' for IE?
I know I can use the following to include statements for IE, but how do I exclude them?
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
Share
edited Aug 29, 2015 at 18:01
Tunaki
137k46 gold badges366 silver badges437 bronze badges
asked Dec 2, 2011 at 14:00
jackjack
4032 gold badges6 silver badges16 bronze badges
1
- You can use the server side to detect if an IE browser is making the request and then not send that script. – david Commented Dec 2, 2011 at 14:12
3 Answers
Reset to default 4Just use ! see here for more info
<!--[if !IE]>
or
<!--[if !(IE 6)]>
For all IE versions:
<!--[if !IE]>
conditional stuff
<![endif]-->
Unfortunately, there's no such mechanism as to exclude a script (i.e. unless the script is targeted at IE only, in which case go see ramblex/karim79's answer).
But ... you could modify your script to check for a global (yeah, I know sigh) variable that - when set - makes the script stop. Something along the line:
// wrap your nice script in an anonymous function
(function(document, undefined) {
if ( window.ie6 === true ) return;
.....
})(document);
Now go on and include the global variable with a conditional tag, like so:
<!--[if lte IE 6]>
window.ie6 = true;
<![endif]-->
Et voila.