【问题标题】:navigator notification alert not working in Cordova导航器通知警报在 Cordova 中不起作用
【发布时间】:2014-11-30 22:27:54
【问题描述】:

我正在尝试使用 Cordova 打印警报,并且仅当我使用 Ripple Chrome 扩展程序模拟我的应用时它才有效。

在我的三星 Galaxy S3 中,单击按钮时没有任何反应。

我正在使用 Cordova 3.6.3-0.2.13。 我在我的项目中添加了以下插件: org.apache.cordova.dialogs 和 org.apache.cordova.vibration。 (如果我输入“cordova plugins ls”,它们都会出现)

<html>
<head>
<script type="text/javascript" charset="utf-8">

      function getInfo() {
         navigator.notification.alert(
                 'Model: ' + device.model,  // message
                 null,         // callback
                 'Info',            // title
                 'Ok'                  // buttonName
         );
     }
    </script>

    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
</head>
<body>
    <div class="app">
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
        <button id="gobutton" type="button" onclick="getInfo()">CLICK ME</button>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</body>
</html>

虽然我的 index.js 是:

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

你能帮帮我吗?提前致谢

【问题讨论】:

  • 尝试将 getInfo() 函数移到 index.js 的底部

标签: javascript android cordova phonegap-plugins cordova-plugins


【解决方案1】:

道森的评论应该有效。

您可以在 Cordova 文档页面上看到: http://docs.phonegap.com/en/2.2.0/cordova_notification_notification.md.html#notification.alert

代码:

navigator.notification.alert

是在加载科尔多瓦库之后。

【讨论】:

    猜你喜欢
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 2020-11-10
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多