The location object is probably best known for enabling you to navigate to a new URL, and we've seen that as long ago as Chapter 4. Here's that example; in this case, we let the user enter a URL and make the browser navigate to that URL when she clicks a button (Listing 04-06.html on the web site): <HTML> <HEAD> <TITLE> Navigate to an URL </TITLE> <SCRIPT LANGUAGE = "JavaScript"> <!-- function Jump() { window.location.href = document.form1.text1.value } // --> </SCRIPT> </HEAD> <BODY> <H1>Navigate to an URL</H1> <FORM NAME = "form1"> <BR> <INPUT TYPE = TEXT NAME="text1" SIZE = 80> <BR> <BR> <INPUT TYPE = BUTTON Value="Navigate to URL" ONCLICK="Jump()"> </FORM> </BODY> </HTML> You can see this script at work in Chapter 4, in Figure 4.7, where the user just has to enter a URL into a text field and click a button to navigate to that URL. This is one of the most powerful aspects of JavaScript, in factthe ability to navigate the browser under programmatic control. |