Location Object


Location object

The Location object contains information about the current URL.

The Location object is part of the window object, it can be accessed through related properties in the format window.location.xxx .

NoteNote: There is no published standard that applies to the Location object, but it is supported by all browsers.


Location Object Properties

PropertyDescription
hashReturns the anchor portion of a URL
hostReturns the hostname and port of a URL
hostnameReturns the hostname of the URL
hrefReturns the full URL
pathnameReturns the URL pathname.
portReturns the port number used by a URL server
protocolreturns a URL protocol
searchReturns the query part of a URL

Location Object Methods

MethodDescription
assign()Load a new document
reload()Reload current document
replace()Replace the current document with the new document