JQuery - 使用navigator.notification.alert

Gar*_*ary 2 customization notifications alert jquery-mobile cordova

我要求弹出窗口显示自定义标题(从应用程序的index.html看起来看起来很俗气).

我尝试了以下链接末尾的建议:

使用PhoneGap HTML在iOS中自定义JavaScript警报

所以我在脚本部分的index.html中添加了以下代码:

   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();
        }

    }
Run Code Online (Sandbox Code Playgroud)

UPDATE

我有以下警报代码;

if ((inputNumber>maxAllowed))
        {
        showMessage("The input is too high.",null,"Warning","Warning");
        }
Run Code Online (Sandbox Code Playgroud)

编译应用程序后,这不起作用.

以下是在index.html中:

    document.addEventListener("deviceready", onDeviceReady, false);

            function onDeviceReady() {
            // Now safe to use the PhoneGap API
            }

<function shown above is here>
Run Code Online (Sandbox Code Playgroud)

知道为什么这还不行吗?从index.html显示

谢谢.

亲切的问候,

加里谢尔吉尔

Gaj*_*res 8

此错误告诉您该功能navigator.notification不存在.

通常这是因为:

  1. Phonegap/Cordova未在HEAD中初始化
  2. 函数未在deviceready事件中初始化.基本上,在完全初始化cordova.js之前无法调用函数.

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

  • 啊,谢谢你.我会尽快重新编译应用程序(只是想弄清楚如何在横向上获得某个屏幕).谢谢. (2认同)