Javascript Browser Window confirm() Method

Introduction

Display a confirmation box:

confirm("Press a button!");

Click the button to display a confirm box.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w  w w . j a v  a  2 s.  c o m*/
  confirm("Press a button!");
}
</script>

</body>
</html>

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

The confirm() method returns true if the user clicked "OK", and false otherwise.

confirm(message);

Parameter Values

Parameter Type Description
message String Optional. Specifies the text to display in the confirm box



PreviousNext

Related