1. Home
  2. Javascript
  3. Document location

Document location gives you an access to an object containing useful information about the current URL and methods for updating and redirecting. Use the dot notation to access object properties and methods.

#javascript#document
document.location // returns a full list of methods and properties
document.location.hash // returns a string marked with the # sign 
document.location.hostname // returns the base domain name
document.location.href // returns a full url including query string and hash
document.location.pathname // returns the the page or a subfolder
document.location.search // returns a string marked with the ? sign 

document.location.reload() // forces page reload
document.location.assign('new-url') // redirects to a new url and saves it to the browsing history
copy
Full Javascript cheatsheet