@cc Conditional Compilation - IE (Internet Explorer) | UA - User Agents

Standards Based Development

JavaScript browser sniffing is a bit dubious at the best of time, but if you wish to target IE versions from 5 to 8 (and presumably 9 too) use conditional comments. If you don't want them in your x/html you can use conditional comments in jscript too:


<script>
// technically Jscript http://blogs.msdn.com/b/ie/archive/2010/03/02/how-ie8-determines-document-mode.aspx#9972014
>>>CODE BEGINS
/*@cc_on
 @if (@_jscript_version > 5.7)
      // IE8
 @elif (@_jscript_version == 5.7)
      // IE 6 or IE 7
      // split using test for window.XMLHttpRequest
 @elif (@_jscript_version == 5.6)
     // IE 6
 @elif (@_jscript_version == 5.5)
     // IE 5.5
 @else
     // IE 4 or 5
 @end
@*/
CODE ENDS>>>
</script>