Name
Location — represents and controls browser location
Synopsis
The location
property of
the Window and Document objects refers to a Location object that represents the web address
(the “location”) of the current document. The href
property contains the complete URL of
that document, and the other properties of the Location object each
describe a portion of that URL. These properties are much like the
URL properties of the Link object. When a Location object is used as
a string, the value of the href
property is returned. This means that you can use the expression
location
in place of location.href
.
In addition to representing the current browser location, the
Location object also controls that location. If
you assign a string containing a URL to the Location object or to
its href
property, the web
browser loads and displays that URL. You can also make the browser
load a new document by setting other Location properties to alter
portions of the current URL. For example, if you set the search
property, the browser reloads the
current URL with a new query string appended. If you set the
hash
property, the browser does
not load a new document, but it does create a new history entry. And
if the hash
property identifies
an element of the document, the browser scrolls the document to make
that element visible.
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 ...
Get JavaScript: The Definitive Guide, 6th 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.