JS Location
CSGNetwork FREE Source Code, Javascript Source, and Code Snippets!
CSGNetwork Custom Search
     Bookmark and Share
 
CSGNetwork
Snippets
Calculators
Top Free Apps
Home
Back



Right click this window and select "view source" in order to copy the source for this script.

Location

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>

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. (ie: "section2").
host Specifies the host and domain name of a network host. (ie: www.mysite.com).
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.
protocol Specifies the protocol portion of the URL (ie: http:).
search Specifies the query portion of the URL (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.



Bookmark and Share
Registered® Trademark™ and Copyright© 1973 - CSG, Computer Support Group, Inc. and CSGNetwork.Com All Rights Reserved