Categories:

JavaScript Kit > JavaScript Reference > Here

Location

Last updated: July 6th, 2008

Location contains information about the current URL of the browser. The most common usage of Location is simply to use it to automatically navigate the user to another page:

<script type="text/javascript">
window.location="http://www.google.com"
</script>

Related Tutorials

Properties

Properties Description
 

We will use the URL "http://www.mysite.com/good.htm#section2" as basis below to explain the various properties.

hash Specifies the anchor portion of the URL, including the leading hash. (ie: "#section2").
host Specifies the hostname and port (if available) of a URL. (ie: "www.mysite.com" or "www.mysite.com:563").
hostname Specifies the hostname portion of the URL (ie: "www.mysite.com").
href Specifies the entire URL.
pathname Specifies the path name of the URL (ie: "/good.htm").
port Specifies the port portion of the URL (ie: "563" within the host "www.mysite.com:563").
protocol Specifies the protocol portion of the URL, including the trailing colon (ie: "http:" or "https:").
search Specifies the query portion of the URL, including the question mark (ie: "?sort=alpha")

Methods

Note: "[]" surrounding a parameter below means the parameter is optional.

Methods Description
reload([forceGet]) Reloads the current document. If "forceGet" set to true, document is completely reloaded even if server reports it hasn't been modified since last reload. Default is false.
replace(url) Loads the specified URL over the current history entry. Example(s)

Examples

replace(url)

location.replace("http://www.cnn.com") //Loads CNN.com in browser and overwrites the most recent history entry with it.


Reference List

Right column

CopyRight (c) 2018 JavaScript Kit. NO PART may be reproduced without author's permission. Contact Info