Wednesday, August 14, 2013

Alert Pop-up in PhoneGap

Using the native notification or browser alert pop-up

This is a continuation from the Previous notes: Creating an Android App with PhoneGap and Eclipse
Purpose: Display the Alert pop-up before the application display its contents.

Step 1: Create the main.js
In the project's assets/www create js folder, then create a new text file and name it as main.js
Place the following contents in assets/www/js/main.js

 var app = {  
      showAlert: function (message, title) {  
    if (navigator.notification) {  
     navigator.notification.alert(message, null, title, 'OK');  
    } else {  
     alert(title ? (title + ": " + message) : message);  
    }  
      },  
   initialize: function() {  
        var self = this;  
     self.showAlert('This is how its done','Info');  
   }  
 };  
 app.initialize();  

Step 2: Load main.js from index.html
Edit index.html. Immediately after the body tag place the following 1 line.

 <script src="js/main.js"></script>  

Step 3: Test the application.
See previous posting on how to do this.

1 comment:

Unknown said...

these steps are very precautionary! it helps in my mass notification software

Blog Archive