88Part IIJavaScript TutorialThe appearance of this (Web site directory) and two

88Part IIJavaScript TutorialThe appearance of this and two other JavaScript dialog boxes (described next) has changedsince the first scriptable browsers. In older browser versions (as shown in Figure 8-2), thebrowser inserted words clearly indicating that the dialog box was a JavaScript Alert. Different browsers display different title bars whose content cannot be altered by script. Youcan change only the other message content. All three dialog box methods are good cases for using a windowobject s methods without thereference to the window. Even though the alert()method is technically a windowobjectmethod, no special relationship exists between the dialog box and the window that generatesit. In production scripts, I usually use the shortcut reference: alert( This is a JavaScript alert dialog. ); window.confirm() methodThe second style of dialog box presents two buttons (Cancel and OK in most versions onmost platforms) and is called a confirm dialog box (see Figure 8-3). More importantly, this isone of those methods that returns a value: trueif the user clicks OK, falseif the user clicksCancel. You can use this dialog box and its returned value as a way to have a user make adecision about how a script progresses. Figure 8-3:A JavaScript confirm dialog box(IE6/WinXP style). Because the method always returns a Boolean value, you can use the evaluated value of theentire method as a condition statement in an ifor if…elseconstruction. For example, inthe following code fragment, the user is asked about starting the application over. Doing socauses the default page of the site to load into the browser. if (confirm( Are you sure you want to start over? )) { location.href = index.html ; } window.prompt() methodThe final dialog box of the windowobject, the prompt dialog box (see Figure 8-4), displays amessage that you set and provides a text field for the user to enter a response. Two buttons, Cancel and OK, enable the user to dismiss the dialog box with two opposite expectations: canceling the entire operation or accepting the input typed into the dialog box. Figure 8-4:A JavaScript prompt dialog box (IE6/WinXP style).