Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Window confirm() method

Window confirm() method

Window Object Reference 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


Example

Example

Display a confirmation box reminding the visitor what to click:

function myFunction(){

    var x;

    var r=confirm("Press a button!");

    if (r==true){

        x="You pressed the OK button!";

    }

    else{

        x="You pressed the Cancel button!";

    }

    document.getElementById("demo").innerHTML=x;

}

Try it »


Window Object Reference Window Object