What's the correct way to pass in tilde path in javascript in order to get the relative path?
I have a tilde path. I would like to convert it into client url
var path = "~/Presentation/Resources/Images/masterPage/cleanup.png";
var a = '<%=Page.ResolveClientUrl(" '+path+' ") %>';
var b = '<%=ResolveUrl("~/Presentation/Resources/Images/masterPage/cleanup.png") %>';
alert("var a-->"+a);
alert("var b-->"+b);
although the code above seems the same, the results I obtain for var a and var b are very different.
Result
var a --> ~/Presentation/Resources/Images/masterPage/cleanup.png
var b --> ../../Resources/Images/masterPage/cleanup.png
I have a variable that stores the path, but I failed to get the result ex开发者_高级运维actly like var b. What can I do for var a so that I can get the result like var b?
The methods you are calling, ResolveClientUrl and ResolveUrl, are different. ResolveClientUrl tells you the URL relative to the page you are on; ResolveUrl tells you the URL relative to the site root. You can find a more thorough description at http://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx
There is also more info in this other SO question.
精彩评论