Block script in IE

2019-06-20 08:35发布

I have a fancy script that is nice, but not essential and surprise surprise, doesn't play nice with IE. How do I 'comment 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]-->

3条回答
2楼-- · 2019-06-20 09:00

Just use ! see here for more info

<!--[if !IE]>

or

<!--[if !(IE 6)]>
查看更多
Melony?
3楼-- · 2019-06-20 09:04

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.

查看更多
Melony?
4楼-- · 2019-06-20 09:17

For all IE versions:

<!--[if !IE]>
conditional stuff
<![endif]-->
查看更多
登录 后发表回答