Name

Location: represents and controls browser location — JavaScript 1.0: Object → Location

Synopsis

locationwindow.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, “#results”. 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, "http://www.oreilly.com:1234“.

hostname

A read/write string property that specifies the hostname portion of a URL—for example, "http://www.oreilly.com“.

href

A read/write string property that specifies the complete text of the document’s URL, unlike other Location properties that 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, ...

Get JavaScript: The Definitive Guide, 5th 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.