Location

The location object controls the URL shown in the browser window.

Properties

hash

FF, IE 3

Part of the URL following a hash mark

Example:

window.location.hash = "where_to_go";

This will cause the browser to jump to the position of the current page that has the anchor <a name = "where_to_go"></a>.

host

FF, IE 3

Hostname and port of a URL

For example, if the URL is http://www.feedmag.com:80/index.html, the host is www.feedmag.com:80.

hostname

FF, IE 3

Domain of the URL shown in the browser

Example:

if (window.location.hostname == "www.nostarch.com")
{
    alert("welcome to No Starch Press");
}

href

FF, IE 3

Full path of the page shown. Changing href causes the browser to load the specified page.

For example:

window.location.href = "http://www.nostarch.com/index.html"; ...

Get The Book of JavaScript, 2nd 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.