Skip to content

Instantly share code, notes, and snippets.

@alvarezmauro
Last active May 8, 2018 02:45
Show Gist options
  • Save alvarezmauro/8f425c1567bc068fdaf2 to your computer and use it in GitHub Desktop.
Save alvarezmauro/8f425c1567bc068fdaf2 to your computer and use it in GitHub Desktop.
JS - Get absolute URL using a string variable.
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
// Usage
getAbsoluteUrl('/something'); // mauroalvarez.com/something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment