Using window.confirm

suggest change

The window.confirm() method displays a modal dialog with an optional message and two buttons, OK and Cancel.

Now, let’s take the following example:

result = window.confirm(message);

Here, message is the optional string to be displayed in the dialog and result is a boolean value indicating whether OK or Cancel was selected (true means OK).

window.confirm() is typically used to ask for user confirmation before doing a dangerous operation like deleting something in a Control Panel:

if (window.confirm("Are you sure you want to delete this?")) {
    deleteItem(itemId);
}

The output of that code would look like this in the browser:

If you need it for later use, you can simply store the result of the user’s interaction in a variable:

var deleteConfirm = window.confirm("Are you sure you want to delete this?");

Notes

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Getting started:
* Using window.confirm

Table Of Contents
0 Getting started
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde