Window confirm()Method

Window 对象参考手册Window Object

Definition and Usage

The confirm() method is used to display a dialog box with a specified message and OK and Cancel buttons.

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

Syntax

confirm(message)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the confirm() method


Examples

Examples

Display a confirmation box to remind visitors what to click:

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

Try it Yourself »


Window 对象参考手册Window Object Other Extensions