3

I am running a DotNetNuke CMS website built on ASP.NET framework.

I have a few scripts in my page skin that I do not want to run on IE8 and below. I've been google'ing around, and I've found this IE conditional statement.

<![if gt IE 8]>

As per http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx , this snippit should include the code inbetween for any browser that is greater than IE8. I attempted to use this conditional statement in the following manner:

<![if gt IE 8]>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f21643b21c50811"></script>
<![endif]-->

However, this does not seem to work, and the scripts do not run on any browser. Is there a better way to accomplish this goal? Is there a syntax error in my code?

Thanks for your help! Alex

Alex Ritter
  • 1,009
  • 3
  • 18
  • 40
  • It will work in IE 9, but IE 10 stopped supporting conditional comments. http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx . You can use conditional compilation, that is supported in all versions. Here's a post about it: http://stackoverflow.com/questions/16135814/check-for-ie-10/16135889#16135889 – Ian Aug 20 '13 at 21:58
  • Check your syntax: `` – elclanrs Aug 20 '13 at 21:59

3 Answers3

3

The conditional comment should be:

<!--[if IE 8]>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f21643b21c50811"></script>
<![endif]-->

with the two dashes after the exclamation point.

It's called a "conditional comment" because it's actually an HTML comment:

<!-- this is a comment -->.

Internet Explorer (until IE9) makes an exception and parse the comments with the special format

<!--[ if ... ]
...
<![endif]-->

as an instruction, but for any other browsers is just a comment and it'll be ignored.

1

Just wanted to add some updated information that as of IE10 and above, conditional comments are not supported, so using a conditional like so,

<!--[if gt IE 8]>
<script type="text/javascript"   src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f21643b21c50811"></script>
<![endif]-->

which includes a gt operator (per question post), means the script will actually only show up in IE9, effectively making it the same in function as writing:

<!--[if IE 9]>
<script type="text/javascript"   src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f21643b21c50811"></script>
<![endif]-->

End of conditional support article: https://msdn.microsoft.com/en-us/library/ie/hh801214%28v=vs.85%29.aspx

Conditional comments resource: https://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx

timmcliu
  • 1,769
  • 1
  • 13
  • 12
0

Just adding an information to load different scripts for IE10+ and IE9-.

    <!--[if lt IE 10]>
         <script src="scripts/jquery-1.x.x.min.js" type="text/javascript"></script>
    <!--<![endif]-->
    <!--[if gte IE 10]><!-->
    <script src="jquery-2.x.x.min.js" type="text/javascript"></script>
    <!--<![endif]-->

Note the code at line 4, this informs IE10+ that the script tag at line 5 is not a comment

The above conditional statement will load jquery-1.x.x in IE9 or lower and loads jquery-2.x.x for IE10+ versions.

Kira
  • 1,403
  • 1
  • 17
  • 46