What’s the difference between following relative paths?
<script type="text/javascript" src="../Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="~/Scripts/jquery-1.2.6.js"></script>
- Which refers what?
-
e.g. I have a web app names ASPWP1 and folder structure as follows
-
ASPWP1->Folder1
- ASPWP1->Folder1->JS1.js
- ASPWP1->Folder1->Sample1.aspx
- ASPWP1->Folder2
- ASPWP1->Folder2->JS2.js
- ASPWP1->Folder2->Sample2.aspx
- ASPWP1->Folder3->JS3.js, JS4.js
- How to refer JS1 in sample1.aspx?
- How to refer JS1 in Sample2.aspx?
- How to refer JS3/JS4 in Sample1.aspx
Please guide me in understanding relative paths.
Thanks in advance
The tilde (~) refers to HttpRuntime.AppDomainAppVirtualPath which is usually the route of the virtual directory.
Have you tested: < script type=”text/javascript” src=”~/Scripts/jquery-1.2.6.js”>
I’m surprised it would actually reference the file without a runat=”server” tag as JavaScript would not be able to determine the value of HttpRuntime.AppDomainAppVirtualPath.
I have included a MSDN source which you should read to help you understand this better.
http://msdn.microsoft.com/en-us/library/ms178116.aspx