Skip to content

Instantly share code, notes, and snippets.

@reqshark
Created January 27, 2017 19:46
Show Gist options
  • Save reqshark/91b065d20c411a7b088aa2fcf722c9bd to your computer and use it in GitHub Desktop.
Save reqshark/91b065d20c411a7b088aa2fcf722c9bd to your computer and use it in GitHub Desktop.
parse url
function parseURL (url) {
var div = document.createElement('div');
div.innerHTML = '<a></a>';
div.firstChild.href = url; // Ensure href is properly escaped
div.innerHTML = div.innerHTML; // Run current innerHTML back through parser
return div.firstChild.origin || '//' + div.firstChild.hostname; // or case is for IE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment