I am experiencing issues with the phonegap device ready event. I am testing under iOS 6.0.
When device ready is fired, the DOM isn't ready. If I bind events to some DOM Elements in a deviceready
event listener, I will receive no notifications because these elements do not exist at this early time.
So what are the best practices for waiting until BOTH have finished loading - DOM and phonegap?
if your are using jquery try this
$(document).ready(function(){
document.addEventListener("deviceready",onDeviceReady,false);
});
function onDeviceReady(){
//write your function body here
}
if your are using javascript only try this
if(document.readyState === "complete") {
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady(){
//write your function body here
}
try something like this:
function onLoad(){
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
// Now safe to use the PhoneGap API
}
Then:
<body onload="onLoad()">
This will ensure the DOM is ready before the deviceready is called
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With