user1104092
user1104092

Reputation:

Calls to phonegap.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?

Upvotes: 1

Views: 2344

Answers (3)

Odegard
Odegard

Reputation: 24

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.

Upvotes: 1

Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40503

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>

Upvotes: 1

ghostCoder
ghostCoder

Reputation: 7655

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(){

});

Upvotes: 0

Related Questions