Skip to content

Instantly share code, notes, and snippets.

@yannbertrand
Last active August 29, 2015 14:25
Show Gist options
  • Save yannbertrand/cfeea28373cd37c36911 to your computer and use it in GitHub Desktop.
Save yannbertrand/cfeea28373cd37c36911 to your computer and use it in GitHub Desktop.
Some window.location tips
// We are on page
// http://www.example.com:8080/search?q=devmo#test
console.log(window.location.href)
// → "http://www.example.com:8080/search?q=devmo#test"
console.log(window.location.origin)
// → "http://www.example.com:8080"
console.log(window.location.protocol)
// → "http:"
console.log(window.location.hostname)
// → "www.example.com"
console.log(window.location.host)
// → "www.example.com:8080"
console.log(window.location.port)
// → "8080"
console.log(window.location.pathname)
// → "/search"
console.log(window.location.search)
// → "?q=devmo
console.log(window.location.hash)
// → "#test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment