Alex
Alex

Reputation: 9041

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... />
<![endif]-->

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

Some assistance would be much appreciated.

Upvotes: 4

Views: 2532

Answers (5)

BoltClock
BoltClock

Reputation: 724112

Try this:

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

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

Upvotes: 10

Buhake Sindi
Buhake Sindi

Reputation: 89179

Just load the script for IE 7 and higher.

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

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

MSDN Reference.

Upvotes: 0

Raynos
Raynos

Reputation: 169451

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]-->

Upvotes: 2

changelog
changelog

Reputation: 4681

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>

Upvotes: 3

Dean Thomas
Dean Thomas

Reputation: 1116

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.

Upvotes: 0

Related Questions