Cordovaでのアプリ開発の中で、確認ダイアログなど必要なときがあります。
Cordovaでダイアログを出したい場合、プラグインを使用しなければいけません。
以下、プラグインのインストール方法とダイアログの出し方です。
①インストール
| 1 2 | cd Cordovaのプロジェクトディレクトリ cordova plugin add cordova-plugin-dialogs | 
②コード編集
②-1 「OK」など選択肢が一つしかないダイアログ。注意書きなどに使う。
| 1 2 3 4 5 6 7 8 9 10 | navigator.notification.alert(     '例:このアイテムは購入済みです',  // message     alertDismissed,         // callback     '例:アイテム購入',            // title     'OK'                  // buttonName ); function alertDismissed() {     // 「OK」を押された時の動作 } | 
②-2 「はい」「いいえ」など確認して選択させるダイアログ。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | navigator.notification.confirm(     '例:このアイテムを削除しますか?', // message      onConfirm,            // callback to invoke with index of button pressed     '例:アイテム削除',           // title     ['はい','やっぱやめる']     // buttonLabels ); function onConfirm(buttonIndex) {     if(buttonIndex === 1){         //アイテムを消す     }else if(buttonIndex === 0 || buttonIndex === 2){         //アイテムを消さない     } } | 
②-3 ダイアログ内で文字を入力させる。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | navigator.notification.prompt(     '例:アイテム名の変更',  // message     onPrompt,                  // callback to invoke     '例:アイテム名を入力してください',            // title     ['OK','やっぱやめる'],             // buttonLabels     'ポーション'                 // defaultText ); function onPrompt(results) {     if(buttonIndex === 1){         //アイテム名を変更する     }else if(buttonIndex === 0 || buttonIndex === 2){         //アイテム名を変更しない     } } | 
②-4 ビープ音を鳴らしたいときに。
| 1 | navigator.notification.beep(2); //鳴らしたい秒数 |