please dont rip this site

The Location Object

The Location object contains information about the current documents location and can be used to manipulate browser navigation.

For a general example for the location object, consider your browser is currently visiting the rather over-complete URL :

all will become clear.

Location Properties
The hash property returns, or sets the URL fragment part of the current location. For example, from the URL above :


would set the variable vFrag to 'findme'.

The host property sets or returns the host section of the current URL. The host section of a URL is basically the hostname property (see below), together with the port property (see below). So, using the above example :

would set vHost to Note the subtle difference between this and the hostname property. (If the current URL does not contain a port setting, then host and hostname are effectively the same).

The hostname property (as mentioned above) is the name of the host computer (either a name, or IP address). For example :


sets the vHostNane variable to

The href property can be regarded as a concatenation of all the other location properties. That is, if the current URL was the one given above for the example, then :


would make vHref be

The pathname property provides the current path for the URL. This is the section in between the hostname (including protocol) if any and the hash, or search (see below) sections (if either exists). For example :


would return example_files/file.html as the contents of the vPathName variable.

As you may suspect, the port property represents any port settings for the current URL. Given the above example,


sets vPort to 80 (the common port for Web servers).

This property represents the protocol currently in use for the displayed document. For example :


sets vProtocol to 'http:'. For commonly used protocols, see the <A HREF="..."> element.

The search property contains information about any search strings in the current URL. For example :

returns 'Stephen' as the contents of the vSearch variable.

Location Methods
The Internet Explorer 4.0 specific method takes one argument (URL). It then loads the document referenced at the URL (if it exists) in place of the currently displayed document. Basically, it performs the same as changing the href property.

The reload method forces a re-loading of the current URL. It should be noted that Netscape decides how to interact with the server for re-loading according to the Network Preference settings (i.e whether the user has set documents to be verified once, all the time, or never). Saying that however, this decision can be over-ruled by specifying a true parameter. This forces the browser to re-load the current document from the server, despite the current users preference settings. For example :


may re-load the document, depending on user preferences, while :


forces Netscape to re-visit the server to retrieve a new copy of the document.
This can be especially useful if your document changes rapidly, avoiding users seeing old copies of the document due to disk/memory caches, or if they are browsing through a proxy/cache server.

This is much like the reload method, except that it loads another document and replaces the history object entry for the previous URL with the new URL loaded. Essentially, this prevents the user from returning to the previous URL, by using the browsers back button. For example, suppose you are at the URL given above for the examples and the following code gets executed :


The browser would navigate to the Microsoft web site and replace the entry in the history object with Unless you'd remembered the previous URL, there would be no navigating back to it.

Location Events
The Location object has no events.

file: /Techref/language/html/ib/Scripting_Reference/loco.htm, 7KB, , updated: 2021/2/5 17:48, local time: 2024/7/25 09:16,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> The Location object</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?


Welcome to!


Welcome to!