调用phonegap.js
当我的按钮被点击时,什么也没有发生。
<button onclick="captureVideo();">Capture Video</button>
我已将phonegap-1.4.1.js 放入WWW 文件夹中。
我已在我的头部包含 。
我按照 PhoneGap API 文档的示例完成了所有支持功能。
<script>
// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}
// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}
// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo();
}
</script>
我对其他外部 js 的其他调用都工作正常。只是phonegap-1.4.1.js 不起作用。我在这里缺少什么?
编辑
当我内联粘贴 PhoneGap js 时,我对这些函数的所有调用都工作正常。所以,我已经确定问题是它从未从外部加载。 Deviceready 警报会告诉我同样的事情,但它不会使其加载。那么问题来了,如何让外部js加载呢?
When my button is clicked, nothing happens.
<button onclick="captureVideo();">Capture Video</button>
I've put phonegap-1.4.1.js in the WWW folder.
I've included <script src="javascript/phonegap-1.4.1.js" type="text/javascript"></script>
in my head section.
I did all the supporting functions, as per PhoneGap API Docs' example.
<script>
// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}
// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}
// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo();
}
</script>
My other calls to other external js all work fine. Just phonegap-1.4.1.js isn't working. What am I missing here?
EDIT
When I pasted the PhoneGap js inline, then all my calls to those functions worked fine. So, I've established that the problem was it never loaded from externally. Deviceready alerts will tell me the same thing, but it doesn't MAKE it load. So, the question remains, how can I get the external js to load?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文件在这里:
但您将其包含在不同的位置:
它没有加载,因为它希望在 javascript 目录中找到该文件,而您已将其放入 www 文件夹中。在 www 文件夹中创建一个目录“javascript”,或者从脚本标记的 src 中删除“javascript”。
The file is here:
But you're including it in a different location:
It's not loading because it expects to find the file inside a javascript directory, while you've put it in the www folder. Make a dir "javascript" inside the www folder, or remove "javascript" from the src in your script tag.
您需要调用
document.addEventListener ..
来确保 PhoneGap 已加载,因此在您的 body onload 上调用 init() 方法并将以下内容放入您的 head 标记中
You need to call
document.addEventListener ..
to ensure PhoneGap loaded, So Call init() method on your body onloadand put the below in your head tag
您需要确保 deviceready 事件正在触发。只有在它触发后你才能进行phonegap api调用
you need to make sure that deviceready event is firing. only after it fires would u be able to make phonegap api calls