最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Block script in IE - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 4

Just 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.

发布评论

评论列表(0)

  1. 暂无评论