This version of the documentation is outdated!
Click here for the latest released version.
notification.confirm
Shows a customizable confirmation dialog box.
navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
- message: Dialog message (
String
) - confirmCallback: - Callback to invoke with index of button pressed (1, 2 or 3) or when the dialog is dismissed without a button press (0), (
Function
) - title: Dialog title (
String
) (Optional, Default: "Confirm") - buttonLabels: Comma separated string with button labels (
String
) (Optional, Default: "OK,Cancel")
Description
Function notification.confirm
displays a native dialog box that is more customizable than the browser's confirm
function.
confirmCallback
The confirmCallback
is called when the user has pressed one of the buttons on the confirmation dialog box.
The callback takes the argument buttonIndex
(Number
), which is the index of the pressed button. It's important to note that the index uses one-based indexing, so the value will be 1
, 2
, 3
, etc.
Supported Platforms
- Android
- BlackBerry OS 5 - 7 and BlackBerry 10
- iPhone
- Windows Phone 7 and 8
- Bada 1.2 & 2.x
- Tizen
- Windows 8
Quick Example
// process the confirmation dialog result
function onConfirm(buttonIndex) {
alert('You selected button ' + buttonIndex);
}
// Show a custom confirmation dialog
//
function showConfirm() {
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
}
Full Example
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// Empty
}
// process the confirmation dialog result
function onConfirm(buttonIndex) {
alert('You selected button ' + buttonIndex);
}
// Show a custom confirmation dialog
//
function showConfirm() {
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
}
</script>
</head>
<body>
<p><a href="#" onclick="showConfirm(); return false;">Show Confirm</a></p>
</body>
</html>
Windows Phone 7 and 8 Quirks
- There is no built-in browser function for
window.confirm
- You can bind
window.confirm
by assigningwindow.confirm = navigator.notification.confirm;
.
- You can bind
- Calls to
alert
andconfirm
are non-blocking and result is only available asynchronously.
Bada 2.x Quirks
confirm
uses the browser's built-inalert
function.
Bada 1.2 Quirks
- Ignore button names, always
'OK|Cancel'
.