Posted By

plugables on 09/09/11


Tagged

url aspnet relative absolute resolve


Versions (?)

Resolve relative Urls from Javascript (for ASP.NET)


 / Published in: JavaScript
 

URL: http://iridescence.no/post/Resolving-relative-URLe28099s-from-JavaScript.aspx

  1. Url = function() { }
  2.  
  3. Url.prototype =
  4. {
  5. _relativeRoot: '<%= ResolveUrl("~/") %>',
  6.  
  7. resolve: function(relative) {
  8. var resolved = relative;
  9. if (relative[0] == '~') resolved = this._relativeRoot + relative.substring(2);
  10. return resolved;
  11. }
  12. }
  13.  
  14. $Url = new Url();
  15.  
  16.  
  17. //Now, anywhere I need to resolve a relative url in a script, I can do this:
  18. var logoUrl = $Url.resolve("~/Images/logo.png");

Report this snippet  

You need to login to post a comment.