17

I am trying to use the alert method, so the native iOS like alertView will popout. Everything works fine, and the alert gets displayed. But the Heading of the Alert is always index.html.

How can i edit the heading of the alert method

user1315906
  • 3,374
  • 8
  • 30
  • 43

2 Answers2

22

You'll want to use navigator.notification.alert() from the PhoneGap API instead. It will allow you to set a title on your alert box.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • 1
    [Updated documentation for PhoneGap 3.3](http://docs.phonegap.com/en/3.3.0/cordova_notification_notification.md.html) – Keith May 19 '14 at 18:49
2

If you don't want to refactor your code, you can override the alert() method with a notification :

window.alert = function (txt) {
   navigator.notification.alert(txt, null, "Alert", "Close");
}

You can custumize the window title : "Alert, and the close button : "Close"

Intuitisoft
  • 1,390
  • 1
  • 9
  • 18
  • null causes issues for me, i had to insert "function() {}" – Ben Taliadoros Oct 01 '14 at 16:33
  • `window.alert()` is synchronous (blocking) whereas `navigator.notification.alert()` is asynchronous (non-blocking). If `window.alert()` is being used in a blocking context, (e.g. `alert(a); doSomething();alert(b);doSomethingElse()`) then doing as this answer suggests may cause issues. – DaveAlden Mar 15 '16 at 12:35