license: > Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

title: notification.alert

notification.alert

Shows a custom alert or dialog box.

navigator.notification.alert(message, alertCallback, [title], [buttonName])
  • message: Dialog message (String)
  • alertCallback: Callback to invoke when alert dialog is dismissed. (Function)
  • title: Dialog title (String) (Optional, Default: “Alert”)
  • buttonName: Button name (String) (Optional, Default: “OK”)

Description

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.

Supported Platforms

  • Android
  • BlackBerry WebWorks (OS 5.0 and higher)
  • iPhone
  • Windows Phone 7 ( Mango )
  • Bada 1.2 & 2.x
  • webOS
  • Tizen

Quick Example

// Android / BlackBerry WebWorks (OS 5.0 and higher) / iPhone / Tizen
//
function alertDismissed() {
    // do something
}

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);

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
    }

    // 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>

Windows Phone 7 Quirks

  • Ignores button names, always uses ‘OK’
  • There is no built in browser alert, so if you want to just write alert(‘foo’); you can assign window.alert = navigator.notification.alert;
  • alert + confirm calls are non-blocking, and result is only available asyncronously.

Bada 2.x Quirks

  • alert uses javascript alert