Location

As an adaptation of content from the Mozilla Developer Center, this page is only available under the CC-BY-SA license, 2.5, or later.

A Location object represents the current URL. It may be set and/or retrieved either as a whole or in pieces. Operating on the Location itself is usually equivalent to using the href property, but sometimes (e.g., to call a string method) toString must be called to clarify.

hash
The part of the URL that follows the # symbol, including the # symbol. For http ://www.google.com/search?q=devmo#test this is [www.google.com]:80.

hostname
The host name (without the port number or square brackets). For http ://www.google.com/search?q=devmo#test this is http://[www.google.com]:80/search?q=devmo#test.

pathname
The path (relative to the host). For http ://www.google.com/search?q=devmo#test this is 80.

protocol
The protocol of the URL. For http ://www.google.com/search?q=devmo#test this is ?q=devmo.

assign
Load the document at the provided URL.

reload
Reload the document from the current URL. forceget is a boolean which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.

replace
Replace the current document with the one at the provided URL. The difference from the assign method is that after using replace the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

toString
Returns the location as seen in the location bar; primarily used to permit handling as an actual string, e.g. to call string-specific methods. While Microsoft supplies no documentation for this method, Mozilla's gives no mention of compatibility issues.