You are here: Reference > JavaScript > client-side > dialog > methods > confirm (window)

confirm method (window)

Browser support:
Displays a confirmation dialog with a message that the user needs to respond to.
The confirmation dialog contains an OK and a Cancel button. Script execution does not continue until the confirm method returns (the user presses the OK or Cancel button or closes the confirmation dialog).
  • To display a notification dialog, use the alert method.
  • To display a prompt dialog, use the prompt method.

Syntax:

object.confirm ([message]);
You can find the related objects in the Supported by objects section below.

Parameters:

message
Optional. String that specifies the text for the message in the dialog box. Default is an empty string. This parameter is required in Firefox.

Return value:

Boolean. One of the following values:
false The confirmation dialog was closed by the Cancel button or by the system Close button.
true The confirmation dialog was closed by the OK button.

Example HTML code 1:

This example illustrates the use of the confirm method:
<head>
    <script type="text/javascript">
        function CanContinue () {
            var confRet = window.confirm ("Do you want to continue the operation?");
            if (confRet) {
                alert ("The operation is continued.");
            }
            else {
                alert ("The operation is stopped.");
            }
        }
   </script>
</head>
<body>
    <button onclick="CanContinue ()">Create a confirmation dialog</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content