Phonegap APINotification for help document translation is the content to be introduced in this article, mainly to understandPhonegap APIDocument Content, detailsPhonegap APIThis document describes the visual, auditory, and tactile notifications of devices.
Method:
- Notification. Alert
- Notification. Confirm
- Notification. BEEP
- Notification. vibrate
- Notification. Alert
Displays a custom warning or dialog box.
- Navigator. Notification. Alert (message, alertcallback, [title], [buttonname]);
- Navigator. Notification. Alert (message, alertcallback, [title], [buttonname]);
Message: Dialog Box Information. (String type)
Alertcallback: the callback function called when the warning dialog box is ignored. (Function type)
Title: The title of the dialog box. (String type) (optional, default value: "alert ")
Buttonname: button name (string type) (optional, default value: "OK ")
Note:
Most phonegap uses the local dialog box to implement this function. However, some platforms simply use the alert function of the browser, which is usually not customizable.
Supported platforms:
Android
BlackBerry (operating system 4.6)
Blackberry webworks (OS 5.0 or later)
IPhone
Simple Example:
- // Android/BlackBerry webworks (OS 5.0 and higher) // iPhone
- Function alertdismissed (){
- // Process
- }
- Navigator. Notification. Alert (
- 'You are the winner! ', // Display information
- Alertdismissed, // warning the ignored callback function
- 'Game over', // Title
- 'Done' // button name
- );
- // BlackBerry (operating system 4.6) // WebOS
- Navigator. Notification. Alert ('you are the winner! ');
- // Android/BlackBerry webworks (OS 5.0 and higher) // iPhone
- Function alertdismissed (){
- // Process
- }
-
- Navigator. Notification. Alert (
- 'You are the winner! ', // Display information
- Alertdismissed, // warning the ignored callback function
- 'Game over', // Title
- 'Done' // button name
- );
-
- // BlackBerry (operating system 4.6) // WebOS
- Navigator. Notification. Alert ('you are the winner! ');
- Complete example:
- View plaincopy to clipboardprint?>
- <HTML>
- <Head>
- <Title> notification exampletitle>
- <SCRIPT type = "text/JavaScript" charset = "UTF-8" src = "phonegap. js"> SCRIPT>
- <SCRIPT type = "text/JavaScript" charset = "UTF-8">
- // Wait for loading phonegap
- Document. addeventlistener ("deviceready", ondeviceready, false );
- // Phonegap loaded
- Function ondeviceready (){
- // Null
- }
- // The warning dialog box is ignored.
- Function alertdismissed (){
- // Process
- }
- // Display a custom warning box
- Function showalert (){
- Navigator. Notification. Alert (
- 'You are the winner! ', // Display information
- Alertdismissed, // warning the ignored callback function
- 'Game over', // Title
- 'Done' // button name
- );
- }
- SCRIPT>
- Head>
- <Body>
- <P> <a href = "#" onclick = "showconfirm (); Return false;"> show confirma> P>
- Body>
- HTML>
- >
- <HTML>
- <Head>
- <Title> notification exampletitle>
-
- <SCRIPT type = "text/JavaScript" charset = "UTF-8" src = "phonegap. js"> SCRIPT>
- <SCRIPT type = "text/JavaScript" charset = "UTF-8">
-
- // Wait for loading phonegap
- Document. addeventlistener ("deviceready", ondeviceready, false );
- // Phonegap loaded
- Function ondeviceready (){
- // Null
- }
- // The warning dialog box is ignored.
- Function alertdismissed (){
- // Process
- }
- // Display a custom warning box
- Function showalert (){
- Navigator. Notification. Alert (
- 'You are the winner! ', // Display information
- Alertdismissed, // warning the ignored callback function
- 'Game over', // Title
- 'Done' // button name
- );
- }
-
- SCRIPT>
- Head>
- <Body>
- <P> <a href = "#" onclick = "showconfirm (); Return false;"> show confirma> P>
- Body>
- HTML>
- Notification. Confirm
A Customizable confirmation dialog box is displayed.
- Navigator. Notification. Confirm (message, confirmcallback, [title], [buttonlabels]);
- Navigator. Notification. Confirm (message, confirmcallback, [title], [buttonlabels]);
Message: Dialog Box Information. (String type)
Confirmcallback: the callback function triggered after the button is pressed. The index (1, 2, or 3) of the pressed button is returned ). (Function type)
Title: The title of the dialog box. (String type) (optional, default value: "Confirm ")
Buttonlabels: A comma-separated button tag string. (String type) (optional, default value: "OK, cancel ")