Shows a custom alert or dialog box.
navigator.notification.alert(message, alertCallback, [title], [buttonName])
String
)Function
)String
) (Optional, Default: “Alert”)String
) (Optional, Default: “OK”)Most Cordova implementations use a native dialog box for this feature. However, some platforms simply use the browser's alert
function, which is typically less customizable.
// Android / BlackBerry WebWorks (OS 5.0 and higher) / iPhone // function alertDismissed() { // do something } navigator.notification.alert( 'You are the winner!', // message alertDismissed, // callback 'Game Over', // title 'Done' // buttonName ); // BlackBerry (OS 4.6) / webOS // navigator.notification.alert('You are the winner!');
<!DOCTYPE html> <html> <head> <title>Notification Example</title> <script type="text/javascript" charset="utf-8" src="cordova-1.6.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 } // alert dialog dismissed function alertDismissed() { // do something } // Show a custom alert // function showAlert() { navigator.notification.alert( 'You are the winner!', // message alertDismissed, // callback 'Game Over', // title 'Done' // buttonName ); } </script> </head> <body> <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p> </body> </html>