Changes

JavaScript Location Object

1,042 bytes added, 16:55, 18 May 2007
New page: The JavaScript ''Location'' object is a child object of the ''Window Object'' and is used to store information about the current URL of the Window object. == Loading a New URL into the Cu...
The JavaScript ''Location'' object is a child object of the ''Window Object'' and is used to store information about the current URL of the Window object.

== Loading a New URL into the Current Window ==

The location object contains a number of methods and properties that enable the JavaScript developer to manipluate the current URL of a window. A commom example is to progammatically change the current window URL. This can be done by assigning a new URL string to the ''href'' property of the Location option:

<pre>
window.location.href="http://www.techotopia.com";
</pre>

== Reading the URL of the Current Window ==

It is also possible to read the URL of the current document. The simplest form of this is to access the ''href'' property of the Location object of the current window:

<pre>
var currentURL=window.location.href;
</pre>

It is also possible to access the various components that go to make up a complete URL. Suppose, for example, that the current URL is:

<tt>http://www.techotopia.com:80/order.cgi?batch=1#intro</tt>