[RESOLVED]Using ResolveClientUrl() in linked JavaScript files

I found that ResolveClientUrl() works as expected when JavaScript is embedded in ASPX page, however it doesn’t resolve anything when external script is referenced in ASPX like this:

    <script src="../Javascript/sessionManagement.js" type="text/javascript"></script>  

Is there a way to make ResolveClientUrl() work in external JS files? I was expected that it would because this file IS included in ASPX page but this is not the case.

I found a rather ugly workaround – to include external JS file in ASPX page like this:

    <script type="text/javascript" language="jscript">
        <!–#include file="../Javascript/sessionManagement.js"–>
    </script>

It works (ResolveClientUrl() actually resolves path) but I’ve never seen external JS files referenced like that and am not sure this is the way to go.

Hi JoeSchmoe115,

You can try the code which are provided by  the link below:

http://stackoverflow.com/questions/26062130/using-resolveclienturl-in-external-javascript-files

<script type="text/javascript">
var myUrl = '<%= ResolveClientUrl("MyURL") %>';
</script>

Best Regards,

Kevin Shen.

Try just placing a code-block within your actual <script> tag and wrap your path within the ResolveUrl() method as seen below :

<script src="<%= ResolveUrl("~/Javascript/sessionManagement.js") %>" type="text/javascript"></script>  

Leave a Reply