JQuery - Using navigator.notification.alert

余生颓废 提交于 2019-12-03 20:56:45

This error tells you that function navigator.notification don't exist.

Usually this is because:

  1. Phonegap/Cordova is not initialized inside a HEAD
  2. Function is not initialized inside a deviceready event. Basically function can't be called before cordova.js is fully initialized.

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        // Now safe to use the PhoneGap API
    }
    

Here is a function I use while testing Phonegap applications on my PC. I remove it when deploying app on mobile device. It's for confirm function, but you can adjust it for alerting and so on.

    // TODO: remove on deploy
    navigator.notification = {
        confirm: function (message, successCallback) {
            successCallback(1);
        }
    };

You are testing in a browser so navigator.notification is undefined. Also It seems that you added the function showMessage but you are not using it. Try with:

showMessage("The value is too high!", null,"Warning", "Warning");

From phone, notice that the callback is not a string. So in your function, you pass it a string and that is causing it a problem.

http://docs.phonegap.com/en/1.0.0/phonegap_notification_notification.md.html

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);

I see this is the case because I am trying to do this also. So unfortunately you cannot override the callback, and you need to "hard Code" it.

flex

I have add the plugin using CLI like :

$ cordova plugin add cordova-plugin-dialogs

and its working fine for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!