Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom JavaScript alerts in iOS using PhoneGap HTML

My app has a couple of JS alerts and it seems to always display the page name like.

index.html

Is there a way to change the index.html to my App's name or custom text.

Example:

My App // Which replaces .index.html
alert("I am an alert box!");
like image 973
Blynn Avatar asked Feb 24 '12 14:02

Blynn


3 Answers

To be able to test on both a desktop browser and PhoneGap application, I suggest to use a dynamic approach as such:

function showMessage(message, callback, title, buttonName) {

    title = title || "default title";
    buttonName = buttonName || 'OK';

    if(navigator.notification && navigator.notification.alert) {

        navigator.notification.alert(
            message,    // message
            callback,   // callback
            title,      // title
            buttonName  // buttonName
        );

    } else {

        alert(message);
        callback();
    }

}
like image 85
Zorayr Avatar answered Nov 13 '22 20:11

Zorayr


Like Simon said check out the notifications it's part of the phonegap API.

You call it like this -

Notification with options:

navigator.notification.confirm(
   "This is my Alert text!",
    callBackFunction, // Specify a function to be called 
    'Alert Title',
    ["Ok", "Awesome"]
);

function callBackFunction(b){
  if(b == 1){
    console.log("user said ok");
  }
  else {
    console.log("user said Awesome");
  }
}

A simple notification -

navigator.notification.alert(
    "This is my Alert text!",
    callBackFunctionB, // Specify a function to be called 
    'Alert Title',
    "OK"
);
function callBackFunctionB(){
    console.log('ok');
}

Hope that helps!

like image 44
Drew Dahlman Avatar answered Nov 13 '22 19:11

Drew Dahlman


Use navigator.notfication.alert as you can provide your own title.

like image 26
Simon MacDonald Avatar answered Nov 13 '22 18:11

Simon MacDonald