Deviceready Not Working In Phonegap Application, How To?
Solution 2:
What @GPRathour provided works because document.addEventListener()
is listening for deviceready
, then if true, running your alert function. I didn't work how you had it because of two reasons:
1) when the DOM loaded and got down to your body tag it was calling OnDeviceReady() and the listener never got the call, so phonegap doesn't know it's ready to run.
2) you would have to call your listener from within a function and use 'false':
functioninit(){
document.addEventListener("deviceready", onDeviceReady, false);
}
functiononDeviceReady(){
alert('123');
}
<body onload="onDeviceReady()"></body>
Check out the phonegap API as to why to use false instead of true in your listener, has to do with the default setting, but it's worth the read to understand how phonegap listeners work.
Solution 3:
Just in case you have the same problem as me, I didn't know is needed to include the cordova.js script in your index.html, you don't have to provide the file or the reference, just include this line:
<scripttype="text/javascript"charset="utf-8"src="cordova.js"></script>
and then Cordova will use the library when compiling, after that the event is dispatched.
Solution 4:
this code work for me
<body onload="init()"></body>
functioninit() {
document.addEventListener("deviceready", onDeviceReady, false);
}
functiononDeviceReady() {
// Now safe to use the Cordova API
}
happy coding.......
Solution 5:
When using PhoneGap 3.0 with WP8 Device Ready will not work because Phonegap.js is NOT INCLUDED in the Visual Studio solution.
The solution is to include it manually for now.
Post a Comment for "Deviceready Not Working In Phonegap Application, How To?"