Skip to content

Instantly share code, notes, and snippets.

@kisin
Last active March 22, 2017 12:20
Show Gist options
  • Save kisin/d6840dd3d70fcd20f858def2b8020784 to your computer and use it in GitHub Desktop.
Save kisin/d6840dd3d70fcd20f858def2b8020784 to your computer and use it in GitHub Desktop.
get absolute url using createelement a
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
// Usage
getAbsoluteUrl('/something'); // https ://example.com/something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment