HTML and CSS Reference
In-Depth Information
Dialog Boxes
4.1 Interacting with the User
Programs like to talk, ask questions, get answers, and respond. In the previous chapter,
we saw how the write() and writeln() methods are used to send the document's output
to the browser. The document is defined in an object and write() and writeln() are meth-
ods that manipulate the document, make it do something. The document object is
defined within a window. The window is also an object and has its own methods.
The window object uses dialog boxes to interact with the user. The dialog boxes are
created with three methods:
4.1.1 The alert() Method
The window's alert() method is used to send a warning to the user or alert him or her to
do something. For example, you might let the user know he or she has not entered his
or her e-mail address correctly when filling out a form, or that his or her browser doesn't
support a certain plug-in, and so on. The alert box is also commonly used for debugging
to find out the results of a calculation, if the program is executing in an expected order,
and so on.
The alert() method creates a little independent window—called a dialog box—that
contains a a user-customized message placed after a small triangle, and beneath it, an
OK button. See Figure 4.1. When the dialog box pops up, all execution is stopped until
the user clicks the OK button in the pop-up box. The exact appearance of this dialog
box might differ slightly on different browsers, but its functionality is the same.
Unlike the write() method, the alert() method doesn't require the window object
name in front of it as window.alert(). Because the window is the top-level browser object,
it doesn't have to be specified. This is true with any window object methods you use.
Search WWH ::

Custom Search