Created
June 11, 2015 14:51
-
-
Save ezmiller/9fe63f6ea2667ecffbb6 to your computer and use it in GitHub Desktop.
A quick way to parse a url using the DOM
This file contains 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
var parseUrl = function(url) { | |
var parser, urlInfo; | |
parser = document.createElement('a'); | |
parser.href = url; | |
urlInfo = { | |
protocol: parser.protocol, | |
hostname: parser.hostname, | |
port: parser.port, | |
pathname: parser.pathname, | |
parsedPathname: parser.pathname.split('/'), | |
search: parser.search, | |
hash: parser.hash, | |
host: parser.host | |
}; | |
return urlInfo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment