An object that resides below the document in the scripting object model. The location object represents the current URL:
![]()
Setting any portion of the location object causes the browser to navigate to the newly constructed URL. The following script navigates to http://www.microsoft.com:
<script language="VBScript"> [some preceding VBScript code] location.href=" http://www.microsoft.com" </script>
href, protocol, host, hostname, port, pathname, search, hash
Gets or sets the compete URL for the location.
location.href [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the complete URL for the location.
Gets or sets the protocol portion of the URL.
location.protocol [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the protocol portion of the URL.
For http://www.microsoft.com, this would return http:.
Gets or sets both the host and port portion of the URL (hostname:port.).
location.host [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the host and port portion of the URL.
For http://www.microsoft.com, this would be www.microsoft.com:80. For file: protocols, this always returns "".
Gets or sets the host portion of the URL, either a name or an IP address.
location.hostname [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the hostname portion of the URL.
For http://www.microsoft.com, this would return www.microsoft.com. For file: protocols, this always returns "".
Gets or sets the port of the URL.
location.port [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the port of the URL.
For http://www.microsoft.com, this returns 80. For file: protocols, this always returns "".
Gets or sets the pathname in the URL.
location.pathname [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the pathname portion of the URL.
Note that the current implementation returns "intdev", not "/intdev" as expected.
For http://www.microsoft.com/intdev, this returns intdev.
Gets or sets the search portion of the URL, if specified.
location.search [=string]
Part Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the search portion of the URL.
For http://www.microsoft.com/intdev?user, this returns ?user. For http://www.microsoft.com/intdev, this returns NULL.
Gets or sets the hash portion of the URL, if specified.
location.hash [=string]
Parameter Description location An object expression that evaluates to a location object. string Optional. The new string value.
Returns a string containing the hash portion of the URL.
Note that current implementation returns "#" always.