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). (
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 WebWorks (OS 5.0 and higher)
- iPhone
- Windows Phone 7 ( Mango )
- Bada 1.2 & 2.x
- Tizen
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-2.1.0.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 Quirks
- Ignores button names, always
'OK|Cancel'. - There is no built-in browser function for
window.confirm- You can bind
window.confirmby assigningwindow.confirm = navigator.notification.confirm;.
- You can bind
- Calls to
alertandconfirmare non-blocking and result is only available asyncronously.
Bada 2.x Quirks
confirmuses the browser's built-inalertfunction.
Bada 1.2 Quirks
- Ignore button names, always
'OK|Cancel'.