This plugin provides access to some native dialog UI elements.
Methods
- navigator.notification.alert
- navigator.notification.confirm
- navigator.notification.prompt
- navigator.notification.beep
Examples
//Beep Examplebeep = function(arg) {
navigator.notification.beep(arg); //arg(a number) stands for how many times it will beep.
};//Alert, Confirm,Prompt Example
//native alert
nativeAlert = function() {
navigator.notification.alert(
‘This is a native alert.’, // message
alertDismissed, // callback
‘Native Alert’, // title
‘Done’ // buttonName
);
};alertDismissed = function() {
alert(“This is a normal alert that called by native alert!”);
};nativeConfirm = function() {
navigator.notification.confirm(
‘Native confirmation example.’, // message
onNativeConfirm, // callback to invoke with index of button pressed
‘Native confirmation’, // title
[‘First’,’Second’,’Third’,’So on’] // buttonLabels
);
};onNativeConfirm = function(buttonIndex) {
switch(buttonIndex) {
case 1: alert(“Button First clicked.”); break;
case 2: alert(“Button Second clicked.”); break;
case 3: alert(“Button Third clicked.”); break;
case 4: alert(“Button So on clicked.”); break;
}
};onPrompt = function(results) {
switch(results.buttonIndex) {
case 1:
alert(“You selected button ” + “Ok ” + ” and entered ” + results.input1);
break;
case 2:
alert(“You selected button ” + “Another ” + ” and entered ” + results.input1);
break;
case 3:
alert(“You selected button ” + “Exit ” + ” and entered ” + results.input1);
break;
}
};
nativePrompt = function() {
navigator.notification.prompt(
‘Please enter your name’, // message
onPrompt, // callback to invoke
‘Registration’, // title
[‘Ok’,’Another’,’Exit’], // buttonLabels
‘Equilibrium’ // defaultText
);
};
Source Documentation:
http://plugins.cordova.io/#/package/org.apache.cordova.dialogs