调用phonegap.js

发布于 2025-01-07 13:35:26 字数 1371 浏览 0 评论 0原文

当我的按钮被点击时,什么也没有发生。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

比忠 2025-01-14 13:35:26

文件在这里:

我已将phonegap-1.4.1.js 放入WWW 文件夹中。

但您将其包含在不同的位置:

我已在我的 head 部分添加了 。< /p>

它没有加载,因为它希望在 javascript 目录中找到该文件,而您已将其放入 www 文件夹中。在 www 文件夹中创建一个目录“javascript”,或者从脚本标记的 src 中删除“javascript”。

The file is here:

I've put phonegap-1.4.1.js in the WWW folder.

But you're including it in a different location:

I've included <script src="javascript/phonegap-1.4.1.js" type="text/javascript"></script> in my head section.

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.

纵情客 2025-01-14 13:35:26

您需要调用 document.addEventListener .. 来确保 PhoneGap 已加载,因此在您的 body onload 上调用 init() 方法

<body  onload="init()">

并将以下内容放入您的 head 标记中

 <script type="text/javascript">
        var onDeviceReady = function() {
            alert("OnDeviceReady fired.");
        };

        function init() {
            document.addEventListener("deviceready", onDeviceReady, true);
        }
    </script>

You need to call document.addEventListener .. to ensure PhoneGap loaded, So Call init() method on your body onload

<body  onload="init()">

and put the below in your head tag

 <script type="text/javascript">
        var onDeviceReady = function() {
            alert("OnDeviceReady fired.");
        };

        function init() {
            document.addEventListener("deviceready", onDeviceReady, true);
        }
    </script>
篱下浅笙歌 2025-01-14 13:35:26

您需要确保 deviceready 事件正在触发。只有在它触发后你才能进行phonegap api调用

document.addEventListener("deviceready", function(){

});

you need to make sure that deviceready event is firing. only after it fires would u be able to make phonegap api calls

document.addEventListener("deviceready", function(){

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文