jQuery-使用navigator.notification.alert [英] JQuery - Using navigator.notification.alert

查看:321
本文介绍了jQuery-使用navigator.notification.alert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a requirement for a popup to appear with a custom heading (having it appear from index.html on an app just looks tacky).

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

I tried the suggestion at the end of the following link:

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

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

So I added the code below to my index.html in the script section:

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

    }

更新

我有以下警报代码;

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

编译应用程序后,此方法不起作用.

After compiling the app, this is not working.

以下是在index.html中:

The following is in index.html:

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

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

<function shown above is here>

有人知道为什么这仍然行不通吗?从index.html显示

Any idea why this is still not working? Showing from index.html

谢谢.

亲切的问候,

Gary Shergill

Gary Shergill

推荐答案

此错误告诉您 navigator.notification 函数不存在.

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

通常这是因为:

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

  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
}

这篇关于jQuery-使用navigator.notification.alert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆