Warning Alert Box

Add a safety layer. Use the confirm() method to force users to verify their intent before performing destructive actions like deleting files or navigating away.

Copy the Script

<script>
function deleteItem() {
    // Returns true if OK is clicked, false if Cancel
    var result = confirm("WARNING: Are you sure you want to delete this item?");
    
    if (result) {
        // Code to delete the item
        alert("Item deleted.");
    } else {
        // Code to cancel the action
        alert("Action cancelled.");
    }
}
</script>

Frequently Asked Questions

An 'alert' only has an OK button and provides information. A 'confirm' box has OK and Cancel buttons, returning 'true' or 'false' respectively to let your code decide what to do next.

No. Native browser dialogs strictly use 'OK' and 'Cancel' (localized to the user's language). To use custom buttons like 'Yes/No', you must build a custom HTML modal.

Yes. The script halts entirely until the user clicks a button.