location object
Contains information about the URL of the currently loaded document, and provides methods to navigate to a new page.
If you need the URLs of the previously visited pages, use the history object.
Syntax:
Properties that reference the object:
| object.location |
Related objects:
|
The base interface, through which you can add new functionalities to the location object, is the Location interface.
Possible members:
Properties:
Sets or returns the subsection (begins with a '#' sign) of the URL assigned to the object. | |||||||
Specifies or retrieves the host name and port of the URL assigned to the object. | |||||||
Specifies or retrieves the host name of the URL assigned to the object. | |||||||
Specifies or returns the location of the destination. | |||||||
Specifies or retrieves the path component of the URL assigned to the object (relative to the host). | |||||||
Sets or retrieves the port component of the URL assigned to the object. | |||||||
Sets or retrieves the protocol component of the URL assigned to the object. | |||||||
Sets or returns the subsection (begins with a '?' sign) of the URL assigned to the object. |
Methods:
assign | Overrides the location of the current document, so it effectively loads a new document. | ||||||
reload | Reloads the current page. | ||||||
replace | Removes the URL of the current document from the document history and loads the document at the specified URL into the current window. |
Example HTML code 1:
This example illustrates the use of the location object:
|
||||
<head> <script type="text/javascript"> function AnalyzeLocation () { var message = ""; message += "hash: " + location.hash + "\n"; message += "host: " + location.host + "\n"; message += "hostname: " + location.hostname + "\n"; message += "href: " + location.href + "\n"; message += "pathname: " + location.pathname + "\n"; message += "port: " + location.port + "\n"; message += "protocol: " + location.protocol + "\n"; message += "search: " + location.search + "\n"; alert (message); } </script> </head> <body> <button onclick="AnalyzeLocation ();">Analyze the location of the current document</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Related pages:
External links:
location (MSDN)
document.location (Mozilla Developer Center)
window.location (Mozilla Developer Center)
document.location (Mozilla Developer Center)
window.location (Mozilla Developer Center)
User Contributed Comments