1

hi i am making phonegap aap. My requirement is remove header from alert box and from confirm boxes .My code for confirm box is

navigator.notification.confirm(
"Are you sure you want to exit ?",
function(buttonIndex){
ConfirmExit(buttonIndex);
},
"Confirmation",
"Yes,No"
);
Varun Nayyar
  • 887
  • 4
  • 20
  • 46
  • can you provide more information? Have you tried to replace the title "Confirmation" with an empty string ("").? – frank Oct 09 '14 at 06:31
  • i tried it.If i replace confirmation with empty string,then confirm box take its default value. – Varun Nayyar Oct 09 '14 at 06:34
  • 1
    can you add some spaces (like " " or a dot ".") instead of empty string and check? It may not be what you expected but something close to what you want. – frank Oct 09 '14 at 06:41
  • adding space removes text.but does not remove the space of title bar.I need to remove that space as well. – Varun Nayyar Oct 09 '14 at 06:44

2 Answers2

3

You are using the org.apache.cordova.dialogs plugin. I tried this and got it to work, here's how:

Search for notification.js file in your project, for eg mine is at:

Users/ft/projectname/platforms/ios/www/plugins/org.apache.cordova.dialogs/www/notification.js

Now, open it and do a find for "confirm", and find this part:

/**
 * Open a native confirm dialog, with a customizable title and button text.
 * The result that the user selects is returned to the result callback.
 *
 * @param {String} message              Message to print in the body of the alert
 * @param {Function} resultCallback     The callback that is called when user clicks on a button.
 * @param {String} title                Title of the alert dialog (default: Confirm)
 * @param {Array} buttonLabels          Array of the labels of the buttons (default: ['OK', 'Cancel'])
 */
confirm: function(message, resultCallback, title, buttonLabels) {
    var _title = (title || "Confirm");
    var _buttonLabels = (buttonLabels || ["OK", "Cancel"]);

    // Strings are deprecated!
    if (typeof _buttonLabels === 'string') {
        console.log("Notification.confirm(string, function, string, string) is deprecated.  Use Notification.confirm(string, function, string, array).");
    }

and just remove the "Confirm" word and leave it blank as:

var _title = (title || "Confirm"); --> var _title = (title || "");

And now for the alert part just find for "Alert" and you will find similar code above just do:

var _title = (title || "Alert"); --> var _title = (title || "");

I am using Cordova 3.6 and the plugin I mentioned above (so get use that plugin URL and try once too if initially you don't get it) and this worked great for me, and as you can see I'm editing from the www inside platforms/iOS so I run from Xcode itself, try that too.

Try and let me know.

allwynmasc
  • 393
  • 5
  • 18
  • yes it worked..thanks a lot.One more question,do you know how to change its color?? – Varun Nayyar Oct 09 '14 at 12:17
  • I am confused about cordova and phonegap .Please check this http://stackoverflow.com/questions/26276903/is-it-possible-to-build-cordova-app-online . and thanks a lot – Varun Nayyar Oct 09 '14 at 12:22
  • well Phonegap was bought by adobe and went on to become a premium paid product and cordova is the open source version basically. I think cordova fits all our developing needs for various platforms and then you can upload the apps to istore/play etc. – allwynmasc Oct 09 '14 at 12:33
  • but i think for cordova we need to install all platforms SDK's (ios,android,) locally,So that we can build app for all platforms.Am i right?? – Varun Nayyar Oct 09 '14 at 12:37
  • you only need to add platforms you want to make the app for and yes you need that particular SDKs installed, for apple you will to install MAC OS or you can read up about intelliJ for windows, not sure. The index.html is where you do all the coding and whatever plugins you add will be added to all your platforms at once to maintain the cross platform nature. – allwynmasc Oct 09 '14 at 12:42
  • @varun change color for the title bar only or for the whole alert/confirm box? – allwynmasc Oct 11 '14 at 05:08
1

It almost not possible to remove the title at all due to the various platforms implementations. The APIs are always abstracted in such a way so that it could work on all (or most) platforms. In this way it becomes difficult to modify Dialog or Alters on one platform or another.

Most Cordova implementations use a native dialog box for this feature, but some platforms use the browser's alert function, which is typically less customizable. ( read more)

As the API uses the browser's alert box so it becomes not possible to modify browsers alert/dialog. ( read this )

I would suggest to use any third party free js library like JQuery, alertyfiy, bootboxjs etc

Community
  • 1
  • 1
AAhad
  • 2,805
  • 1
  • 25
  • 42
  • You are confusing between browsers and cordova. Browsers would mean firefox etc, cordova uses a webview to load the app and the plugins use the OS features to display alerts etc. The JS alert in a browser can't be modified due to security reasons. – allwynmasc Oct 11 '14 at 07:54
  • No, its not confusing. – AAhad Oct 11 '14 at 08:07