Location object contains information about
the current documents location and can be used to manipulate browser navigation.
For a general example for the location object, consider your browser is currently visiting the rather over-complete URL :
all will become clear.
hash property returns, or sets the URL fragment part of
the current location. For example, from the URL above :
would set the variable
vFrag to 'findme'.
host property sets or returns the host section of the current
URL. The host section of a URL is basically the hostname property (see below),
together with the port property (see below). So, using the above example
vHost to www.htmlib.com:80. Note the subtle difference
between this and the hostname property. (If the current URL does not contain
a port setting, then host and hostname are effectively the same).
hostname property (as mentioned above) is the name of the
host computer (either a name, or IP address). For example :
vHostNane variable to www.htmlib.com
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 :
pathname property provides the current path for the URL.
This is the section in between the hostname (including protocol) if any and
the hash, or search (see below) sections (if either exists). For example
would return example_files/file.html as the contents of the
As you may suspect, the
port property represents any port settings
for the current URL. Given the above example,
vPort to 80 (the common port for Web servers).
This property represents the protocol currently in use for the displayed document. For example :
vProtocol to 'http:'. For commonly used protocols, see
search property contains information about any search strings
in the current URL. For example :
returns 'Stephen' as the contents of the
The Internet Explorer 4.0 specific method takes one argument (URL). It then 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
reload method forces a re-loading of the current URL. It
should be noted that Netscape decides how to interact with the server for
re-loading according to the Network Preference settings (i.e whether the
user has set documents to be verified once, all the time, or never). Saying
that however, this decision can be over-ruled by specifying a true
parameter. This forces the browser to re-load the current document from the
server, despite the current users preference settings. For example :
may re-load the document, depending on user preferences, while :
forces Netscape to re-visit the server to retrieve a new copy of the
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.
This is much like the
reload method, except that it loads another
document and replaces the
history object entry
for the previous URL with the new URL loaded. Essentially, this prevents
the user from returning to the previous URL, by using the browsers back button.
For example, suppose you are at the URL given above for the examples and
the following code gets executed :
The browser would navigate to the Microsoft web site and replace the www.htmlib.com entry in the history object with http://www.microsoft.com Unless you'd remembered the previous URL, there would be no navigating back to it.
The Location object has no events.
© 1995-1998, Stephen Le Hunte
|file: /Techref/language/html/ib/Scripting_Reference/loco.htm, 7KB, , updated: 2021/2/5 16:48, local time: 2022/1/21 10:02,
|©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.massmind.org/techref/language/html/ib/Scripting_Reference/loco.htm"> The Location object</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to www.massmind.org!