Window confirm()Method
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
![]()
![]()
![]()
![]()
![]()
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;
}
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 Object Other Extensions