← Plugins / Dialogs (Notification)
This Apache Cordova plugin gives your app native alert, confirm and prompt dialogs — plus a
device beep — that match the look and feel of the platform. Unlike the browser's built-in
window.alert and window.confirm, these don't block the WebView and
they appear as proper system dialogs, so your app feels at home on the device.
Add the plugin to your Cordova project from the command line:
cordova plugin add cordova-plugin-dialogs
The plugin exposes its functions on the global navigator.notification object. Call them after deviceready has fired:
| Method | Description |
|---|---|
navigator.notification.alert(message, callback, [title], [buttonName]) | Shows a single-button native alert. The callback runs when the dialog is dismissed. |
navigator.notification.confirm(message, callback, [title], [buttonLabels]) | Shows a dialog with multiple buttons. The callback receives the 1-based index of the button that was pressed; 0 means the dialog was dismissed without a choice. |
navigator.notification.prompt(message, callback, [title], [buttonLabels], [defaultText]) | Shows a dialog with a text field. The callback receives a results object of the form {buttonIndex, input1}. |
navigator.notification.beep(times) | Plays the device's notification beep the given number of times. |
Ask the user to confirm a destructive action and act on the button they chose:
document.addEventListener("deviceready", onReady, false);
function onReady() {
navigator.notification.confirm(
"Delete this item?",
function(i) {
if (i === 1) {
removeItem();
}
},
"Confirm",
["Delete", "Cancel"]
);
}
deviceready — the navigator.notification object isn't available before then.prompt, the text the user typed comes back as results.input1.window.alert and window.confirm, which freeze the WebView and look out of place on a native device.