[英]Cordova dialog plugin not working
I've been stuck on this issue for 10+ hours now and I'm having no luck in fixing it by myself. 我已经在这个问题上停留了十多个小时,而且我自己没有办法解决这个问题。 The problem is that I'm trying to use this dialog plugin on my Cordova app but its not working.
问题是我试图在我的Cordova应用程序上使用此对话框插件,但无法正常工作。 I don't even think that the deviceready script is working.
我什至不认为deviceready脚本有效。
Any questions feel free to ask 有任何问题请随时询问我(们
www/index.html: 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>
The <plugin name="cordova-plugin-dialogs" spec="^1.3.3" />
is in config.xml <plugin name="cordova-plugin-dialogs" spec="^1.3.3" />
位于config.xml中
Your code in <script>
tag seems alright. 您在
<script>
标记中的代码似乎还不错。 If you have added the dialogs
plugin using - 如果您使用-添加了
dialogs
插件
cordova plugin add cordova-plugin-dialogs
that should work fine. 那应该工作正常。
And don't add src="cordova.js"
for the script containing your code. 并且不要为包含您的代码的脚本添加
src="cordova.js"
。 Just do this - 只是这样做-
<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>
If it still doesn't work, can you inspect in Google Chrome , see and list the error messages under Console
tab? 如果仍然无法使用,您可以在Google Chrome浏览器中进行检查,在
Console
选项卡下查看并列出错误消息吗? There might be some error before that <script>
if that onDeviceReady()
is not triggered. 如果未触发
onDeviceReady()
则在<script>
之前可能存在一些错误。
UPDATE after seeing error messages from here - 在从这里看到错误消息后进行更新 -
<script src="cordova_plugins.js"></script>
That's not required. <script src="cordova_plugins.js"></script>
并非必需。 Plugins are directly called from js
. js
调用。 Cannot read property 'alert' of undefined
=> the plugin is not properly installed. Cannot read property 'alert' of undefined
=>插件未正确安装。 Install it first using cordova plugin add cordova-plugin-dialogs
in cmd. cordova plugin add cordova-plugin-dialogs
安装,然后在cmd中cordova plugin add cordova-plugin-dialogs
dialogs。 <script src="js/index.js"></script>
. <script src="js/index.js"></script>
。 As you are doing everything inside <script>
tag, you don't need index.js
or its js
contents (has errors). <script>
标记内进行所有操作时,不需要index.js
或其js
内容(有错误)。 I reinstalled windows 10 and reinstalled cordova as a whole. 我重新安装了Windows 10,并重新安装了Cordova。 Now all plugins work :) sorry if this isnt the answer you wanted but it worked for me!
现在所有插件都可以工作了:)很抱歉,如果这不是您想要的答案,但是对我有用! Have a good day!
祝你有美好的一天!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.