locationNN 2   IE 3   DOM 1

There is one location object in each window or frame. The object stores all information about the URL of the document currently loaded into that window or frame. By assigning a new URL to the href property of the location object, you instruct the browser to load a new page into the window or frame. This is the primary way of scripting the loading of a new page:

location.href = "newPage.html"

A script in one frame can reference the location object in another frame to load a new document into that other frame:

parent.otherFrameName.location.href = "newPage.html"

Security restrictions prevent a script in one frame from accessing location object information in another frame if the document in the second frame does not come from the same domain as the document with the nosy script. This prevents a rogue script from monitoring navigation in another frame to external web sites. In Navigator 4, you can overcome the security restriction with the help of signed scripts (a topic more suitable for a JavaScript book covering Navigator 4), but the user still has to give explicit permission for a script to access location object information outside the script's domain.

 
 
Object Model Reference
NN [windowRef.]location
IE [windowRef.]location
hashNN 2   IE 3   DOM 1
 Read/Write
 

That portion of a URL following the # symbol, referring to an anchor location in a document. This property contains its data only if the user has explicitly navigated to an anchor, and is not just scrolling to it. Do not include the # symbol when setting the property.

 
Example
location.hash = "section3"
 
Value
String.
 
Default None.
hostNN 2   IE 3   DOM 1
 Read/Write
 

The combination of the hostname and port (if any) of the server that serves up the current document. If the port is explicitly part of the URL, the hostname and port are separated by a colon, just as they are in the URL.

 
Example
if (location.host = "www.megacorp.com:80") {
    ...
}
 
Value
String of hostname, optionally followed by a colon and port number.
 
Default Depends on server.
hostnameNN 2   IE 3   DOM 1
 Read/Write
 

The combination of the hostname of the server (i.e., a "two-dot" address consisting of server name and domain) that serves up the current document. The hostname property does not include the port number.

 
Example
if (location.hostname = "www.megacorp.com") {
    ...
}
 
Value
String of hostname (server and domain).
 
Default Depends on server.
hrefNN 2   IE 3   DOM 1
 Read/Write
 

The complete URL of the document loaded in the window or frame. Assigning a URL to this property is how you script navigation to load a new document into the window or frame (although Internet Explorer also offers the equivalent window.navigate( ) method).

 
Example
location.href = "http://www.megacorp.com"
 
Value
String of complete or relative URL.
 
Default None.
pathnameNN 2   IE 3   DOM 1
 Read/Write
 

The pathname component of the URL. This consists of all URL information following the last character of the domain name, including the initial forward slash symbol.

 
Example
location.pathname = "/images/logoHiRes.gif"
 
Value
String.
 
Default None.
portNN 2   IE 3   DOM 1
 Read/Write
 

The port component of the URL, if one exists. This consists of all URL information following the colon after the last character of the domain name. The colon is not part of the port property value.

 
Example
location.port = "80"
 
Value
String (a numeric value as string).
 
Default None.
protocolNN 2   IE 3   DOM 1
 Read/Write
 

The protocol component of the URL. This consists of all URL information up to and including the first colon of a URL. Typical values are: "http:", "file:", "ftp:", and "mailto:".

 
Example
if (location.protocol == "file:") {
    statements for treating document as local file
}
 
Value
String.
 
Default None.
assign( )NN 2   IE 3   DOM n/a

assign("URL")

This method was intended to be hidden from view of scripters, but remains available for now. It performs the same action as assigning a URL to the location.href property. The assign( ) method is listed here for completeness and should not be used.

 
Returned Value
None.
 
Parameters
URL A string version of a complete or relative URL of a document to be loaded into a window or frame.
reload( )NN 3   IE 4   DOM 1

reload([unconditional])

Performs a hard reload of the document associated with the location object. This kind of reload resets form elements to their default values (for a soft reload, use history.go(0)). By default the reload( ) method performs a conditional-GET action, which retrieves the file from the browser cache if the file is still in the cache (and the cache is turned on). To force a reload from the server, force an unconditional-GET by adding the true Boolean parameter.

 
Returned Value
None.
 
Parameters
unconditional An optional Boolean value. If true, the browser performs an unconditional-GET to force a reload of the document from the server, rather than the browser cache.
replace( )NN 3   IE 4   DOM 1

replace("URL")

Loads a new document into the reference window and replaces the browser's history listing entry of the current document with the entry of the new document. Thus, some interim page that you don't want appearing in history (to prevent the Back button from ever returning to the page) can be removed from the history and replaced with the entry of the newly loaded document.

 
Returned Value
None.
 
Parameters
URL A string version of a complete or relative URL of a document to be loaded into a window or frame.