0

I do get it to read html and use regular js and jQuery methods, but it gives me nothing when I try to use these commands.

These are before my script:

<script src="phonegap.js"></script>
<script src="cordova-1.5.0.js"></script>

Doing this:

var text = "grewrfar";
document.write(text);

...works fine, while for instance:

var text = device.uuid;
document.write(text);

...does not.

Also, I saw some people using navigator before the commands:

var text = navigator.device.uuid;
document.write(text);

This didn't work either.

How do I get it to work? Googling does not get me near a discussion about this, so I'm guessing I'm doing something really stupid. Just a nudge in a direction to look would be greatly appreciated. Thanks!

Henrik
  • 673
  • 8
  • 18

2 Answers2

1

It looks like you are trying to access Phonegap's API before the onDeviceReady event is being fired.

Add this to your JS -

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {    //This will fire only when the Phonegap lib is fully loaded
   console.log(device.uuid);
}
Raoul George
  • 2,807
  • 1
  • 21
  • 25
  • Although, actually now the console.logs don't show up. document.write works fine and shows in the app, but console.log doesn't show up anywhere. Nor where these things show up: "Simulator","uuid":"62e0ca2cdd1850a58d7004f9d27e252900000000","platform":"iPhone Simulator","gap":"1.5.0","version":"6.1","connection":{"type":"wifi"}};". Any idea? – Henrik Aug 13 '13 at 06:07
  • Are you testing this on a simulator? – Raoul George Aug 13 '13 at 06:09
  • Yes (comment requires more letters than 3) – Henrik Aug 13 '13 at 06:10
  • If you are using Eclipse, check the DDMS perspective. Is it not showing up there? – Raoul George Aug 13 '13 at 06:12
  • 1
    Check this post - http://stackoverflow.com/questions/13357568/how-to-see-phonegap-javascript-log-messages-on-xcode-console – Raoul George Aug 13 '13 at 06:20
1

Try this Example..

   // Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is ready
    //
    function onDeviceReady() {
        var element = document.getElementById('result');

        element.innerHTML = 'Device UUID: '     + device.uuid ;
    }

under Body Tag..

<p id="result">Loading device properties...</p>
Shafi PS
  • 371
  • 5
  • 18