JavaScript Location

JavaScript Location


One of the most used instances of JavaScript is location. Location represents the URL or web page address. Location can be used to determine the current URL and also to change the URL to a different page or site.

The location of this page is:

The above script showed how to "see" the current window URL. Now what about changing that URL to a new location? Using a simple form button, the visitor can be linked over to a new page or site.

A couple things should be noticed in the above coding.

  • The use of single quotes around the URL. This is so the coding is not confused with the surrounding double quotes of the OnClick command.
  • The semi-colon after the URL. As with most JavaScript commands, this too is ended with a semi-colon to show it's ending.

One great thing about this is the available use of a button instead of an image for navigation. Many people like the button visually over an image. It creates a sort of "depressed" effect as the visitor clicks on it.

Table of Contents