In JavaScript, it is possible to overwrite native functions. It could for instance be the alert function which we would do like this:
window.alert = function(message){ //Our new alert function };
We can then create our custom version of the alert box, however we would like it to be.
If we would like to, we could also just run the original function while doing some extra stuff. Like in the following example where we log the message to the console.
window.old_alert = window.alert;</code> window.alert = function(message){ console.log(message); old_alert(message); };
The following example is taken from a Phonegap project, where the alert function is overwritten by using the dialogs plugin.
https://github.com/apache/cordova-plugin-dialogs/blob/master/doc/index.md
And now for the example:
window.old_alert = window.alert; window.alert = function(message){ if(typeof(navigator) != 'undefined' && typeof(navigator.notification) != 'undefined' && typeof(navigator.notification.alert) != 'undefined'){ navigator.notification.alert( message, function(){}, getLanguageString('DIALOG_TITLE', 'My custom title'), getLanguageString('DIALOG_OK', 'Ok') ); } else { old_alert(message); return; } };