Phonegap deviceready vs document ready

cordova, javascript

Solution

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

    }

Problem

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?

Original source

Related problems