Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created November 7, 2012 00:29
Show Gist options
  • Select an option

  • Save jeffreyiacono/4028708 to your computer and use it in GitHub Desktop.

Select an option

Save jeffreyiacono/4028708 to your computer and use it in GitHub Desktop.
url parsing in js
// tested in chrome
link = document.createElement("a")
// <a></a>
link.setAttribute("href", "https://whatever.com:3000/some-page?foo=bar#baz")
// undefined
link.href
// https://whatever.com:3000/some-page?foo=bar#baz
link.protocol
// https:
link.host
// whatever.com:3000
link.hostname
// whatever.com
link.port
// 3000
link.pathname
// /some-page
link.search
// ?foo=bar
link.hash
// #baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment