Window confirm() Method

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# Window confirm() Method

Window Object

## Example

Display a confirmation box:

confirm("Press a button!");
Try it yourself »

## Definition and Usage

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

A confirm box is often used if you want the user to verify or accept something.

Note: The confirm box takes the focus away from the current window, and forces the browser to read the message. Do not overuse this method, as it prevent the user from accessing other parts of the page until the box is closed.

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

## Browser Support

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

## Syntax

confirm("sometext")

## Parameter Values

Parameter | Description
--- | ---
sometext | Optional. Specifies the text to display in the confirm box. This parameter is required in Firefox.

## Return Value

Type | Description
--- | ---

Boolean

A boolean value indicating whether "OK" or "Cancel" was clicked in the dialog box:

- true - the user clicked "OK"
- false - the user clicked "Cancel" or the "x" (close) button that is available in all major browsers, except Firefox.

## More Examples

## Example

Display a confirm box, and write what the user clicked:

var r = confirm("Press a button!");
if (r == true)
{
x = "You pressed OK!";
}
else
{
x = "You pressed Cancel!";
}
Try it yourself »

## Example

Confirm box with line-breaks:

confirm("Press a button!\nEither OK or Cancel.");
Try it yourself »

Window Object

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE