Script block in IE

I have a fancy script that is a nice, but not substantial and unexpected surprise, not very pleasant with IE. How can I โ€œcommentโ€ for IE?

I know that I can use the following to include statements for IE, but how to exclude them?

<!--[if IE 6]> Special instructions for IE 6 here <![endif]--> 
+6
source share
3 answers

Just use it! see here for more information

 <!--[if !IE]> 

or

 <!--[if !(IE 6)]> 
+4
source

For all versions of IE:

 <!--[if !IE]> conditional stuff <![endif]--> 
+3
source

Unfortunately, there is no mechanism to exclude a script (i.e. unless the script is targeting IE, in which case go to ramblex / karim79 answer).

But ... you can change your script to check a global variable (yes, I know a sigh) that - when set - stops the script. Something along the line:

 // wrap your nice script in an anonymous function (function(document, undefined) { if ( window.ie6 === true ) return; ..... })(document); 

Now enable and enable the global variable with the conditional tag, for example:

 <!--[if lte IE 6]> window.ie6 = true; <![endif]--> 

Et voila.

0
source

All Articles