HTML and CSS Reference
In-Depth Information
10.1.5 The location Object
The location object is a property of the window object and is used to access the URL of
the document currently loaded in the window. In previous examples, we have seen loca-
tion as a window property, but because it is really also an object itself, it also has proper-
ties used to describe the different parts of a URL (see Table 10.13).
If you are writing a page containing frames, the entire page might not be picked up
by a search engine, such as Yahoo! or Google. Anyone linking to your page via the search
engine will only get part of the page, not the complete frameset. Also, when a page is
divided into frames, the visitor cannot bookmark the page if the browser is not pointing
to the top frameset. The location object can be used to make sure the topmost window
is the one currently viewed in the browser. (See the section “Using the top Property to
Keep the Main Window Out of a Frame” on page 310.)
FORMAT
JavaScript: window.location.href = "URL";
JavaScript: window.location.replace("URL");
EXAMPLE
JavaScript: window.location.href = "http://www.legos.com/";
JavaScript: window.location.replace("http://www.legos.com/");
Table 10.13 Properties of the location Object
Property
What It Describes in the URL
hash
If it exists, the anchor part.
host
The hostname:port.
hostname
The hostname.
href
The entire URL.
pathname
The pathname.
port
The port number.
protocol
The protocol and colon.
search
The query string.
 
 
Search WWH ::




Custom Search