Name
Location — represents and controls browser location
Availability
JavaScript 1.0; enhanced in JavaScript 1.1
Synopsis
location window
.location
Properties
The properties of a Location object refer to the various portions of the current document’s URL. In each of the following property descriptions, the example given is a portion of this (fictitious) URL:
http://www.oreilly.com:1234/catalog/search.html?q=JavaScript&m=10#results
-
hash
A read/write string property that specifies the anchor portion of the URL, including the leading hash (#) mark. For example: “#result”. This portion of the document URL specifies the name of an anchor within the document.
-
host
A read/write string property that specifies the hostname and port portions of the URL. For example, “www.oreilly.com:1234”.
-
hostname
A read/write string property that specifies the hostname portion of a URL. For example “www.oreilly.com”.
-
href
A read/write string property that specifies the complete text of the document’s URL, unlike other Location properties which specify only portions of the URL. Setting this property to a new URL causes the browser to read and display the contents of the new URL.
-
pathname
A read/write string property that specifies the pathname portion of a URL. For example “/catalog/search.html”.
-
port
A read/write string (not a number) property that specifies the port portion of a URL. For example “1234”.
-
protocol
A read/write string property that specifies the protocol portion of a URL, including ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.