Skip to content

Instantly share code, notes, and snippets.

@Kydoh
Last active December 15, 2016 09:28
Show Gist options
  • Save Kydoh/715d74c88494fe11116821233e2ad53a to your computer and use it in GitHub Desktop.
Save Kydoh/715d74c88494fe11116821233e2ad53a to your computer and use it in GitHub Desktop.
Parse a given URL.
/**
* Parse a given URL.
*
* @param {string} url
* @return {Object}
*/
function parseUrl(url)
{
var parser = document.createElement('a');
parser.href = url;
return {
hash: parser.hash.substr(1),
host: parser.hostname,
path: parser.pathname,
port: parser.port,
protocol: parser.protocol.slice(0, -1),
query: parser.search.substr(1)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment