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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access