Created
January 27, 2017 19:46
-
-
Save reqshark/91b065d20c411a7b088aa2fcf722c9bd to your computer and use it in GitHub Desktop.
parse url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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