Name
Window.confirm( ) — ask a yes-or-no question
Availability
JavaScript 1.0
Synopsis
window
.confirm(question
)
Arguments
-
question
The plain text (not HTML) string to be displayed in the dialog box. It should generally express a question you want the user to answer.
Returns
true
if the user clicks the OK button; false
if the
user clicks the Cancel button.
Description
The
confirm( )
method displays the specified
question
in a dialog box that pops up over
window
. The appearance of the dialog box
is platform-dependent, but it generally contains graphics that
indicate that the user is being asked a question. The dialog box
contains OK and Cancel buttons that the user can use to answer
the question. If the user clicks the OK button, confirm( )
returns true
. If the user clicks Cancel, confirm( )
returns
false
.
The dialog box that is displayed by the confirm( )
method is modal -- that is, it blocks all
user input to the main browser window until the user dismisses the
dialog box by clicking on the OK or
Cancel buttons. Since this method
returns a value depending on the user’s response to the dialog
box, JavaScript execution pauses in the call to confirm( )
, and subsequent statements are not executed until the
user responds to the dialog box.
Usage
Note that the question
displayed in the dialog box is a string of plain text, not formatted HTML. You can use the newline character, “\n”, in your strings to break your question across multiple lines. You can also do some rudimentary formatting ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.