Search code examples
jqueryasp.netasp.net-ajaxscriptmanager

Use ScriptReference and ScriptManagerProxy to load script only if IE 8 or earlier?


I got the ScriptManager and ScriptManagerProxy to talk to jquery using this technique. But the ScriptReference tag doesn't seem to have a way to deal with this:

<!--[if lte IE 8]>
<script language="javascript" 
type="text/javascript" 
src="../Scripts/excanvas.min.js"></script>
<![endif]-->

Is there a way to use the ScriptManager to do that, or do I need to roll my own? (At the moment, I'm just using the script manager to calculate the right number of ../.. symbols to put before the address of the script.)


Solution

  • Unfortunatly client-side techniques like the conditional comments used do not mix with server-side techniques. I believe the only way to do this with the ScriptManager would be to programatically add the scripts to the page if your condition is met.

    If you are more concerned with executing the script then delivering it, you can do something like this:

    <!--[if lte IE 8]> 
    var isLteIe8 = true;
    <![endif]--> 
    

    And then, in your script, wrap it with a if(typeof(isLteIe8) !== 'undefined') {...}