Browser confirm
Display a dialog box with a customisable message and two buttons - "OK" and "Cancel".
These dialog boxes take the focus away from the current window, forcing the user to read the message. Use them carefully to verify or accept something, as it prevents users from accessing other parts of the page until the dialog is closed.
The JavaScript method returns true
if the user clics "OK", and false
otherwise.
<button class="button primary" onclick="confirmRemoval();">Remove</button>
The confirm()
method only takes one argument - the message. This can be a single string or a concatenation of strings.
Use \n
to insert line breaks.
function confirmRemoval() {
let userConfirmation = confirm("Are you sure you want to remove \n\nBlack recycling bin");
if (userConfirmation) {
// true
} else {
// false
}
}