Search w3schools.com:

SHARE THIS PAGE

Window confirm() Method

Window Object Reference Window Object

Definition and Usage

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.

This method returns true if the visitor clicked "OK", and false otherwise.

Syntax

confirm(message)


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The confirm() method is supported in all major browsers.


Example

Example

Display a confirm box, and alert what the visitor clicked:

<html>
<head>
<script>
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
  {
  alert("You pressed OK!")
  }
else
  {
  alert("You pressed Cancel!")
  }
}
</script>
</head>
<body>

<input type="button" onclick="disp_confirm()" value="Display a confirm box">

</body>
</html>

Try it yourself »


Window Object Reference Window Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]