This presents a modal dialog containing the confirmation message and two buttons, OK and Cancel. This is useful because you often need confirmation from a user.
This method is useful for debugging. An example showing how it can be used for debugging a recursive function is given below.
Note that the text that is presented in the dialog is plain unformatted text and you cannot use HTML text in the dialog box.
The title bar of the dialog box cannot be changed from its default setting which tells you that the dialog was invoked by JavaScript. In some browsers, it may just display the name of the browser. This is intended to stop script programmers from masquerading their dialog boxes as those of operating system diagnostics and login screens.
The confirm() dialog box is modal and blocking. The script must wait for a response from the user.
When the user clicks on either of the buttons, the result returned by the method indicates which one was chosen. The true value indicates the OK button was clicked and false indicates the Cancel button.
// Example showing the use of a confirm() dialog to // debug recursive calls provided by Martin Honnen. function showTime() { if (confirm('Time is: ' + new Date() + '. Show again?')) { setTimeout('showTime()', 1000 * 5); } } showTime();
Prev | Home | Next |
Window.closed | Up | Window.crypto |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |