how to render the relative path with tilde into ../../ of relative path in jquery/javascript?

前端 未结 4 574
离开以前
离开以前 2021-02-06 16:50

Well, i understand my title is a bit confusing. I will state it clearly below with the example.



        
4条回答
  •  感动是毒
    2021-02-06 17:38

    Try this: http://weblogs.asp.net/joelvarty/archive/2009/07/17/resolveurl-in-javascript.aspx

    In the master page for the site, put this:

    
    

    Then, in your javascript file, put this function:

    function ResolveUrl(url) {
        if (url.indexOf("~/") == 0) {
            url = baseUrl + url.substring(2);
        }
        return url;
    }
    

    You could have put the function right in the master page, but then you wouldn’t get intelli-sense on it for the rest of your code. Now you can call ResolveUrl with ~/ right from javascript.

    Why do you need this on clientside? Use servercontrols(runat=server) and you can use tilde to resolve URL on server.

提交回复
热议问题