Skip to content

Instantly share code, notes, and snippets.

@marco-kretz
Last active July 6, 2017 13:16
Show Gist options
  • Save marco-kretz/a1a3ebd9fae877225ce2005178a92cc1 to your computer and use it in GitHub Desktop.
Save marco-kretz/a1a3ebd9fae877225ce2005178a92cc1 to your computer and use it in GitHub Desktop.
JavaScript: Extract hostname from URL
function getUrlHost(url) {
var parser = document.createElement('a');
parser.href = url;
return parser.hostname;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment