Absolute path to Javascript

Many time we face a problem of JavaScript path

Like you have given path in Master page like "../a.js" so, if you have page at "../../../default.aspx" position it will not import this Js into your page or you will face problem with JS.

So if you want to use a perfect path for your JS use Resolve URL method.

For ex. <script type="text/javascript" src="<%=ResolveUrl("~/js/example.js")%>"></script>

This is the right way work with Dot Net and JS

No comments: