4

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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Alex
  • 8,875
  • 2
  • 27
  • 44

5 Answers5

10

Try this:

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

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

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
3

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>
changelog
  • 4,646
  • 4
  • 35
  • 62
2

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]-->
Raynos
  • 166,823
  • 56
  • 351
  • 396
0

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.

Dean Thomas
  • 1,096
  • 1
  • 10
  • 25
0

Just load the script for IE 7 and higher.

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

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

MSDN Reference.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228