In the cordova application example via cordova create ... , the following code listens for the deviceready event:
bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); },
This is good, but what happens when an event leaves before I can listen to it? As an example, replace the code from the sample application (see above) as follows:
bindEvents: function() { setTimeout(function () { document.addEventListener('deviceready', this.onDeviceReady, false); }, 2000) },
In this example, this.onDeviceReady is never called. There would be no better and more reliable way to check if the cordova is ready? Something like that:
bindEvents: function() { setTimeout(function () { if (window.cordovaIsReady) { this.onDeviceReady() } else { document.addEventListener('deviceready', this.onDeviceReady, false); } }, 2000) },
javascript events cordova ready
Shawn
source share