我正在做一个项目,我需要使用 navigator.notification.alert ...
作为 alert()
的替代品(因为 alert( )
在顶部有一个标签,上面写着 index.html
)。
我正在使用适用于 iOS 的 PhoneGap View 应用程序来测试此应用程序,它不允许我在任何地方调用该方法 (navigator.notification.alert()
)。
这是我做的:
- 使用
phonegap plugin add ...
安装插件 - 调用方法
... .alert(...)
由于我对 Phonegap 和 Cordova 还很陌生,所以我想要一份实际使用该插件所需的所有内容的列表。
是否有任何我需要导入的 JavaScript 文件?有没有办法将插件导入到我的 HTML 中?我可以列出使用任何 PhoneGap 插件需要做的所有事情吗?
更新 1
即使在创建了一个新的 phonegap 应用程序之后,我也没有得到任何 cordova.js 文件:
最佳答案
尝试添加平台(它将添加插件所需的 cordova.js 文件)
cordova platform add android/ios
然后构建
cordova build
可能报告了 Phonegap 问题 here和 here .(由于它没有添加 cordova.js
文件)
Do call any plugins after device ready because that makes plugins available. If you will call plugins directly then you may get plugins
undefined
.
例如
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
// Empty
}
// alert dialog dismissed
function alertDismissed() {
// do something
}
// Show a custom alert
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
alertDismissed, // callback
'Game Over', // title
'Done' // buttonName
);
}
</script>
</head>
<body>
<p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
</body>
</html>
问候。
关于javascript - 使用 phonegap 插件需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38581119/