Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Last active December 24, 2015 19:59
Show Gist options
  • Select an option

  • Save westonwatson/6854415 to your computer and use it in GitHub Desktop.

Select an option

Save westonwatson/6854415 to your computer and use it in GitHub Desktop.
Javascript URL Parser Hack
#first line is the actual parser (DOM Hack)
var parser = document.createElement('a');
#below are example usages
parser.href = "http://example-domain:1337/path/?search=query#anchor";
parser.protocol; // => "http:"
parser.hostname; // => "example-example.com"
parser.port; // => "1337"
parser.pathname; // => "/path/"
parser.search; // => "?search=query"
parser.hash; // => "#anchor"
parser.host; // => "example.com:1337"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment