onDeviceReady not firing in PhoneGap hello world app

The correct way is to make sure that document has completely loaded before adding the event listener.

Example:

HTML:

<body onload="onLoad">

JS:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
   //anything you want done after deviceready has fired
}

With jQuery you can use $(document).ready() instead of <body onload="onLoad()">

Example:

$(document).ready() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
   //anything you want done after deviceready has fired
}

Leave a Comment