Packagedom.objects
Classpublic class Location
InheritanceLocation Inheritance Object

Introduced in: DOM 0 
Modified in:  

Contains information about the URL of the document and provides methods for changing that URL.

View the examples

See also

MSDN - location Object
MDC - window.location
W3C - Window.location


Public Properties
 PropertyDefined By
  DOM 0 hash : DOMString
The part of the URL that follows the # symbol, including the # symbol.
Location
  DOM 0 host : DOMString
The host name (without the port number or square brackets).
Location
  DOM 0 hostname : DOMString
This attribute represents the name or IP address of the network location without any port number.
Location
  DOM 0 href : DOMString
Sets or retrieves the entire URL as a string.
Location
  DOM 0 pathname : DOMString
The path (relative to the host).
Location
  DOM 0 port : DOMString
This attribute represents the port number of the network location.
Location
  DOM 0 protocol : DOMString
This attribute represents the scheme of the URI including the trailing colon (:).
Location
  DOM 0 search : DOMString
The part of the URL that follows the ? symbol, including the ? symbol.
Location
Public Methods
 MethodDefined By
  
DOM 0 assign(url:DOMString):void
Load the document at the provided URL.
Location
  
DOM 0 reload(forceget:Boolean):void
Reload the document from the current URL.
Location
  
DOM 0 replace(url:DOMString):void
Replace the current document with the one at the provided URL.
Location
Property Detail
DOM 0 hashproperty
hash:DOMString

Introduced in: DOM 0 
Modified in:  

The part of the URL that follows the # symbol, including the # symbol.

Note: If there is no number sign, this property returns an empty string.


Implementation
    public function get hash():DOMString
    public function set hash(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

hash: #test

DOM 0 hostproperty 
host:DOMString

Introduced in: DOM 0 
Modified in:  

The host name (without the port number or square brackets).

Note: The host property is the concatenation of the hostname and port properties, separated by a colon (hostname:port). When the port property is null, the host property is the same as the hostname property.

Note: The host property may be set at any time, although it is safer to set the href property to change a location. If the specified host cannot be found, an error is returned.


Implementation
    public function get host():DOMString
    public function set host(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

host: [www.google.com]:80

DOM 0 hostnameproperty 
hostname:DOMString

Introduced in: DOM 0 
Modified in:  

This attribute represents the name or IP address of the network location without any port number.

Note: If no host name is available, this property returns an empty string.


Implementation
    public function get hostname():DOMString
    public function set hostname(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

hostname: www.google.com

DOM 0 hrefproperty 
href:DOMString

Introduced in: DOM 0 
Modified in:  

Sets or retrieves the entire URL as a string.


Implementation
    public function get href():DOMString
    public function set href(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

href: http://[www.google.com]:80/search?q=devmo#test

This example shows a URL list. The user is taken to the URL selected from the options, if the selection is different from the list's default value.

         <SELECT onchange="window.location.href=this.options[this.selectedIndex].value">
             <OPTION VALUE="http://www.microsoft.com/ie">Internet Explorer</OPTION>
             <OPTION VALUE="http://www.microsoft.com">Microsoft Home</OPTION>
             <OPTION VALUE="http://msdn.microsoft.com">Developer Network</OPTION>
         </SELECT>
DOM 0 pathnameproperty 
pathname:DOMString

Introduced in: DOM 0 
Modified in:  

The path (relative to the host).


Implementation
    public function get pathname():DOMString
    public function set pathname(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

pathname: /search

DOM 0 portproperty 
port:DOMString

Introduced in: DOM 0 
Modified in:  

This attribute represents the port number of the network location.


Implementation
    public function get port():DOMString
    public function set port(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

port: 80

This example function returns the port property of two a elements.

         <script>
         function getPort() {
             alert ("FTP: " + oFtp.port + "\n" + "HTTP: " + oHttp.port);
         }
         </script>
         
         <a href="ftp://www.microsoft.com" onclick="getPort();" id=oFtp>ftp</a>
         <a href="http://www.microsoft.com" onclick="getPort();" id=oHttp>http</a>
DOM 0 protocolproperty 
protocol:DOMString

Introduced in: DOM 0 
Modified in:  

This attribute represents the scheme of the URI including the trailing colon (:).

Note (IE): The protocol property specifies how to transfer information from the host to the client. Windows Internet Explorer supports several predefined protocols, including http and ftp.

Note (IE): The document, img, and location objects expose the protocol property as read-only. location.protocol property returns the initial substring of a URL, including the first colon (for example, http:). However, document.protocol returns the expanded text of the protocol acronym. For example, it returns the http protocol as Hypertext Transfer Protocol.


Implementation
    public function get protocol():DOMString
    public function set protocol(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

protocol: http:

DOM 0 searchproperty 
search:DOMString

Introduced in: DOM 0 
Modified in:  

The part of the URL that follows the ? symbol, including the ? symbol.


Implementation
    public function get search():DOMString
    public function set search(value:DOMString):void

See also


Example
You can read them to get information about the current URL or set them to navigate to another URL. The example contains the value of the property of the following URL: http://[www.google.com]:80/search?q=devmo#test

search: ?q=devmo

Send a string of data to the server by modifying the search property:

         function sendData(dat) {
             window.location.search = dat;
         }
         
         // in html: <button onclick="sendData('Some data');">Send data</button>
Method Detail
DOM 0 assign()method
public function assign(url:DOMString):void

Introduced in: DOM 0 
Modified in:  

Load the document at the provided URL.

Parameters

url:DOMString — The URL of the document to load.

See also

DOM 0 reload()method 
public function reload(forceget:Boolean):void

Introduced in: DOM 0 
Modified in:  

Reload the document from the current URL.

Parameters

forceget:BooleanNot in W3 specification 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.

See also

DOM 0 replace()method 
public function replace(url:DOMString):void

Introduced in: DOM 0 
Modified in:  

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.

Parameters

url:DOMString — The URL to insert into the session history.

See also

Examples
Replace the current document with the one at the given URL:
     function goMoz() {
         window.location = "http://www.mozilla.org";
     } 
     
     // in html: <button onclick="goMoz();">Mozilla</button>