I have an asp.net application containing pages that lie in multiple folder. I have my .js files also in one "JS" folder and I have added their reference in head of master page like:
<script type="text/javascript" src="JS/jquery.min.js"></script>
Now when I am on home page, the script loads fine. But when I am on some other page that is present in another folder(Physics for example), the path gets appended and hence I get the error:
Failed to load resource: the server responded with a status of 404 (Not Found)
Similar thing is happening for my image paths and <a>
tags also.
Now I want to give paths with respect to root path something like:
~/JS/VerticalMenu.js
But this ~
is not taking me to the root of my application. Do I need to set where ~
should lead to? And if yes then where and how??
Try this:
The @Charlie Kilian answer is a workable solution however you can also specify a base URL for all the relative URLs in your page by base tag in head of your html page.
If it's an ASP.NET application, you can access the root by prefixing the path
~/
:You can also try prefixing the path with just
/
: