Freelance Writing Jobs | Today's Articles | Sign In

 
Browse Sections

Location Object


Location Objects Properties

The Location object contains information about the current documents location and can be used to manipulate browser navigation. Consider your browser is currently visiting the URL  which complete address is:

http://www.some.com:80/files/file.htm#fi... 

The location object properties for this example will be as follows.

Hash

The hash property returns, or sets the URL fragment part of the current location. For above example,

aHash=self.location.hash

would set the variable aHash to 'find'.

Host

The host property sets or returns the host section of the current URL. The host section of a URL is basically the hostname property, together with the port property (see below). So, using the above example :

aHost=self.location.

would set aHost to 'www.some.com:80'.

Hostname

The hostname property is the name of the host computer (either a name, or IP address). For the given example :

aHostName=self.location.hostname 

sets the aHostNane variable to 'www.some.com'. Note the slow difference between this and the hostname property. (If the current URL does not contain a port setting, then host and hostname are the same).

Href

The href property can be regarded as a concatenation of all the other location properties. That is, if the current URL was the one given above for the example, then :

aHref=self.location

would make aHref be 'http://www.some.com:80/file/file.htm#fin...

Pathname

The pathname property provides the current path for the URL. This is the section in between the hostname (including protocol) and the hash, or search (see below) sections (if either exists). For the example :

aPathName=self.location.

would return file/file.htm' as the contents of the aPathName variable.

Port

The port property represents any port settings for the current URL. Given the above example,

aPort=self.location.port 

sets aPort to 80 (the common port for Web servers).

Protocol

This property represents the protocol currently in use for the displayed document. For the example :

aProtocol=self.location.protocol

sets aProtocol to 'http:'.

Search

The search property contains information about any search strings in the current URL. For the example :

aSearch=self.location.search

returns 'Max' as the contents of the aSearch variable.

Location Object Methods

Assign

The Internet Explorer 4.0 (and above) takes one argument (URL), and loads the document referenced at the URL (if it exists) in place of the currently displayed document. Basically, it performs the same as changing the href property.

Reload

The reload method forces a browser to re-load the current document from the server. This can be especially useful if your document changes rapidly, avoiding users seeing old copies of the document due to disk/memory caches, or if they are browsing through a proxy/cache server.

The copyright of the article Location Object in VB Script is owned by Maxim Karetnikov. Permission to republish Location Object in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic