The Location Object

location object has the location information about the loaded document. location object also provides the general navigation functionality.

The location object is a property of both window and document. Both window.location and document.location point to the same object.

The locaction object has the following properties and methods:

NameDescriptionReturns
assign(<URL>) Navigates to the specified URL.void
hashGets or sets the hash component of the document URL, for example "#myID".string
hostGets or sets the host component of the document URL, for example "www.java2s.com:80".string
hostnameGets or sets the host name component of the document URL, for example "www.java2s.com".string
hrefGets or sets the current document's location, full URL of the loaded page, for example "http://www.java2s.com".string
pathnameGets or sets the path component of the document URL, for example "/Book/HTML-CSS/".string
portGets or sets the port of the document URL, for example "8080".string
protocolGets or sets the protocol of the document URL, for example "http:".. Typically "http:" or "https:"string
reload()Reloads the current document.void
replace(<URL>) Removes the current document and navigates to the one specified by the URL.void
resolveURL(<URL>) Resolves the specified relative URL to an absolute one.string
searchGets or sets the query component of the document URL, for example "?q=javascript".string
toStringReturns the full URL of the loaded pagestring
Home 
  JavaScript Book 
    DOM  

Location:
  1. The Location Object
  2. To get information about the location of the current page
  3. Location assign()
  4. Location.hash
  5. Location.hostname
  6. Location.href
  7. location.pathname
  8. location.port
  9. location.reload()
  10. location.replace()
  11. Location.search
  12. Query String Arguments