Easy Tutorial
❮ Prop Tableheader Abbr Event Onchange ❯

Window confirm() Method


Definition and Usage

The confirm() method is used to display a dialog box with a specified message, along with an OK and a Cancel button.

If the visitor clicks "OK", this method returns true; otherwise, it returns false.

Syntax


Browser Support

All major browsers support the confirm() method.


Example

Example

Display a confirmation box to prompt the visitor on what to click:

function myFunction(){
    var x;
    var r = confirm("Press a button!");
    if (r == true){
        x = "You pressed OK!";
    }
    else{
        x = "You pressed Cancel!";
    }
    document.getElementById("demo").innerHTML = x;
}

❮ Prop Tableheader Abbr Event Onchange ❯