Reputation: 703
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!
Upvotes: 0
Views: 259
Reputation: 2797
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);
}
Upvotes: 1
Reputation: 371
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>
Upvotes: 1