Favorites

DOM Window.confirm() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.confirm()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The confirm() method shows a dialog with OK and Cancel buttons and returns true or false depending on the user's choice.

Description

The confirm() method shows a modal dialog with a message and OK and Cancel buttons, and returns true or false. Like alert(), it blocks the page until answered and can't be styled. A <dialog> lets you write clearer button labels, such as "Delete" and "Keep".

While the dialog is open, all scripts on the page are paused, and the browser may let the user block further dialogs from the page, in which case confirm() returns false immediately. Dialogs are also blocked in sandboxed iframes without the allow-modals permission.

For destructive actions, a custom confirmation in a <dialog> can explain the consequences and use specific button labels, which users read more carefully than a generic OK and Cancel. An undo option after the action is often friendlier still.

Syntax

confirm(message)

Parameters

  • messageThe question to show.

Return Value

true if the user clicked OK, false if they clicked Cancel.

Example

<button id="del" type="button">Delete file</button>
document.getElementById('del').addEventListener('click', () => {
  if (confirm('Delete this file?')) console.log('Deleted');
  else console.log('Kept');
});

Browser Support

The following information will show you the current browser support for the Window.confirm() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee