How to fire deviceready event in Chrome browser (trying to debug phonegap project)
Add this code to your onLoad handler function:
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) { document.addEventListener("deviceready", onDeviceReady, false); } else { onDeviceReady(); }
Event "deviceready" is fired in cordova.js so I don't know a way to detect existence of this event in application code.
Ended up pulling out the StopGap code and having to introduce a tiny delay (have this code running in a separate script than page-specific code):
window.setTimeout(function() { var e = document.createEvent('Events'); e.initEvent("deviceready", true, false); document.dispatchEvent(e);}, 50);
For my mobile site and mobile App I'm using the following code with jQuery:
function init() { ... };if ("cordova" in window) { $(document).on("deviceready", init);} else { $(init);}