开发者

Don't load script in IE6 or less

How can I add a condition so that if a user is running IE6 or less not to load some javascript. I've tried the following, and the <script> doesn't load in any browser:

<!--[if gt IE 6]>
<script blah blah blah... />
<![endif]-->

<!--[if ! IE 6]>
<script blah blah blah... />
开发者_StackOverflow<![endif]-->

<!--[if !IE 6]>
<script blah blah blah... />
<![endif]-->

Some assistance would be much appreciated.


Try this:

<!--[if gt IE 6]><!-->
<script blah blah blah... />
<!--<![endif]-->

The above syntax (with the extra comment delimiters) is explained in this post.


Have you tried head.js? You could load that first, and wrap the actual script loading in a condition, something like:

<script>
if(!isIE6) {
  head.js("path/to/script1.js", "path/to/script2.js");
}
</script>


Use the double negative to exclude scripts from running on a particular IE version

<!-- disabled all javascript in IE6 -->
<!--[if gt IE 6]><!-->

<script type="text/javascript">
    // special not IE6 stuff
</script>

<!--<![endif]-->

Use a simple check to run scripts only on IE6

<!--[if lte IE 6]>

<script type="text/javascript">
    // special IE6 stuff
</script>

<![endif]-->


Give this a read, should help.

http://www.quirksmode.org/css/condcom.html

I've only ever used [if IE 6] before, but worked fine.


Just load the script for IE 7 and higher.

<!-- [if gte IE 7]>
    <script type="text/javascript">

    </script>
<![endif]-->

MSDN Reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜