/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Url = function() { } Url.prototype = { _relativeRoot: '<%= ResolveUrl("~/") %>', resolve: function(relative) { var resolved = relative; if (relative[0] == '~') resolved = this._relativeRoot + relative.substring(2); return resolved; } } $Url = new Url(); //Now, anywhere I need to resolve a relative url in a script, I can do this: var logoUrl = $Url.resolve("~/Images/logo.png");
URL: http://iridescence.no/post/Resolving-relative-URLe28099s-from-JavaScript.aspx