Skip to content

Instantly share code, notes, and snippets.

@rayou
Created June 14, 2015 05:29
Show Gist options
  • Select an option

  • Save rayou/350af2dc517e05e8c798 to your computer and use it in GitHub Desktop.

Select an option

Save rayou/350af2dc517e05e8c798 to your computer and use it in GitHub Desktop.
getAbsoluteUrl
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
// Usage
getAbsoluteUrl('/something'); // http://davidwalsh.name/something
//http://davidwalsh.name/essential-javascript-functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment