繁体   English   中英

Cordova对话框插件不起作用

[英]Cordova dialog plugin not working

我已经在这个问题上停留了十多个小时,而且我自己没有办法解决这个问题。 问题是我试图在我的Cordova应用程序上使用此对话框插件,但无法正常工作。 我什至不认为deviceready脚本有效。

有任何问题请随时询问我(们

www / index.html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content=".." />
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <link href="css/layout-styles.css" rel="stylesheet" type="text/css">
        <link href="css/bootstrap-3.3.7.css" rel="stylesheet" type="text/css">
        <script src="cordova_plugins.js"></script>
        <script src="cordova.js"></script>
        <script src="js/index.js"></script>
        <script src="js/jquery-3.1.1.min.js"></script>
        <script src="js/bootstrap.js"></script>
        <title>Plugins Not Working</title>

        <script src="cordova.js">

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

            function onDeviceReady() {     
                navigator.notification.alert(
                    'Script has loaded',  // message
                    alertDismissed,       // callback
                    'Loaded',             // title
                    'Done'                // buttonName
                );
            };

            function alertDismissd() {
                // do something
            };

         </script>
    </head>
</html>

<plugin name="cordova-plugin-dialogs" spec="^1.3.3" />位于config.xml中

您在<script>标记中的代码似乎还不错。 如果您使用-添加了dialogs插件

cordova plugin add cordova-plugin-dialogs

那应该工作正常。

并且不要为包含您的代码的脚本添加src="cordova.js" 只是这样做-

<script>
document.addEventListener("deviceready", onDeviceReady(), false)

function onDeviceReady() {     
navigator.notification.alert(
   'Script has loaded',  // message
    alertDismissed,       // callback
    'Loaded',             // title
    'Done'                // buttonName
    );
};

function alertDismissd() {
     // do something
};

</script>

如果仍然无法使用,您可以在Google Chrome浏览器中进行检查,Console选项卡下查看并列出错误消息吗? 如果未触发onDeviceReady()则在<script>之前可能存在一些错误。

在从这里看到错误消息后进行更新 -

  1. 删除<script src="cordova_plugins.js"></script>并非必需。 插件直接从js调用。
  2. Cannot read property 'alert' of undefined =>插件未正确安装。 首先使用cordova plugin add cordova-plugin-dialogs安装,然后在cmd中cordova plugin add cordova-plugin-dialogs dialogs。
  3. 删除<script src="js/index.js"></script> <script>标记内进行所有操作时,不需要index.js或其js内容(有错误)。

我重新安装了Windows 10,并重新安装了Cordova。 现在所有插件都可以工作了:)很抱歉,如果这不是您想要的答案,但是对我有用! 祝你有美好的一天!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM