Sunday, May 19, 2024
107
rated 0 times [  112] [ 5]  / answers: 1 / hits: 37195  / 13 Years ago, thu, july 14, 2011, 12:00:00

I'm developing a PhoneGap application and I'd like to be able to debug it in Chrome rather than on the phone. However, I do the initialization of my code in an onDeviceReady() function that is triggered when PhoneGap fires the deviceready event. Since Chrome doesn't fire this event, my code isn't ever initialized.



Here's a stripped down version of my code:



var dashboard = {};

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

dashboard.onDeviceReady = function() {
alert(hello!); //this is never fired in Chrome
};


I've tried using the StopGap code, which basically just does the following:



var e = document.createEvent('Events'); 
e.initEvent(deviceready);
document.dispatchEvent(e);


But when I run that code in the Chrome javascript console, the hello alert still doesn't trigger. What am I doing wrong? Or does chrome just not support firing custom events like deviceready?


More From » google-chrome

 Answers
45

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.


[#91193] Tuesday, July 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kareem

Total Points: 733
Total Questions: 110
Total Answers: 102

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;