Skip to content

Instantly share code, notes, and snippets.

@ezmiller
Created June 11, 2015 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezmiller/9fe63f6ea2667ecffbb6 to your computer and use it in GitHub Desktop.
Save ezmiller/9fe63f6ea2667ecffbb6 to your computer and use it in GitHub Desktop.
A quick way to parse a url using the DOM
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