Skip to content

Instantly share code, notes, and snippets.

@tassoevan
Last active December 20, 2015 04:19
Show Gist options
  • Save tassoevan/6069907 to your computer and use it in GitHub Desktop.
Save tassoevan/6069907 to your computer and use it in GitHub Desktop.
Parsing URLs with DOM
function parseURL(url)
{
var a = document.createElement('a');
a.href = url;
return {
'href': a.href
, 'scheme': a.protocol
, 'host': a.host
, 'port': a.port
, 'path': a.pathname
, 'query': a.search.charAt(0) == '?' ? a.search.substring(1) : null
, 'hash': a.hash.charAt(0) == '#' ? a.hash.substring(1) : null
};
}
@gutoheimer
Copy link

Well done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment