Location Object


location Object

Description

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>

Properties

href, protocol, host, hostname, port, pathname, search, hash


Properties


href Property

Description

Gets or sets the compete URL for the location.

Syntax

location.href [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the complete URL for the location.

Applies To

Location

Properties

protocol, host, hostname, port, pathname, search, hash


protocol Property

Description

Gets or sets the protocol portion of the URL.

Syntax

location.protocol [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the protocol portion of the URL.

Remarks

For http://www.microsoft.com, this would return http:.

Applies To

Location

Properties

href, host, hostname, port, pathname, search, hash


host Property

Description

Gets or sets both the host and port portion of the URL (hostname:port.).

Syntax

location.host [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the host and port portion of the URL.

Remarks

For http://www.microsoft.com, this would be www.microsoft.com:80. For file: protocols, this always returns "".

Applies To

Location

Properties

href, protocol, hostname, port, pathname, search, hash


hostname Property

Description

Gets or sets the host portion of the URL, either a name or an IP address.

Syntax

location.hostname [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the hostname portion of the URL.

Remarks

For http://www.microsoft.com, this would return www.microsoft.com. For file: protocols, this always returns "".

Applies To

Location

Properties

href, protocol, host, port, pathname, search, hash


port Property

Description

Gets or sets the port of the URL.

Syntax

location.port [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the port of the URL.

Remarks

For http://www.microsoft.com, this returns 80. For file: protocols, this always returns "".

Applies To

Location

Properties

href, protocol, host, hostname, pathname, search, hash


pathname Property

Description

Gets or sets the pathname in the URL.

Syntax

location.pathname [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the pathname portion of the URL.

Note that the current implementation returns "intdev", not "/intdev" as expected.

Remarks

For http://www.microsoft.com/intdev, this returns intdev.

Applies To

Location

Properties

href, protocol, host, hostname, port, search, hash


search Property

Description

Gets or sets the search portion of the URL, if specified.

Syntax

location.search [=string]

PartDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the search portion of the URL.

Remarks

For http://www.microsoft.com/intdev?user, this returns ?user. For http://www.microsoft.com/intdev, this returns NULL.

Applies To

Location

Properties

href, protocol, host, hostname, port, pathname, hash


hash

Description

Gets or sets the hash portion of the URL, if specified.

Syntax

location.hash [=string]

ParameterDescription
location An object expression that evaluates to a location object.
string Optional. The new string value.

Return Value

Returns a string containing the hash portion of the URL.

Note that current implementation returns "#" always.

Applies To

Location

Properties

href, protocol, host, hostname, port, pathname, search

© 1996 Microsoft Corporation