I have a simple PhoneGap application as fallows:
PhoneGap powered App
You're binding a handler to deviceready before you've defined the handler.
Correct would be:
function onDeviceReady(){
alert('123')
}
document.addEventListener("deviceready", onDeviceReady, false);
And obviously your phonegap-2.0.0.js file (or other version) should be included in the file before this point.
Make sure below path is correct and both are need to be included into html :
<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
document.addEventListener("deviceready", onDeviceReady, false);
});
function onDeviceReady() {
alert("inside onDeviceReady");
}
</script>
Biggest problem with PhoneGap examples are incorrect javascript syntax. Please be careful with this.. for this question,onDeviceReady should have braces...
document.addEventListener("deviceready", onDeviceReady(), true);
function onDeviceReady() {
alert ('123');
}
Add you event listener for deviceready inside you doc ready...
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
document.addEventListener("deviceready", onDeviceReady, true);
});
function onDeviceReady() {
alert ('123');
}
</script>
You dont want to call onDeviceReady() as this will run the function when you add the listener...
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.
I'm see in your code one problem, in the method, you need add onDeviceReady()
equals here:
document.addEventListener("deviceready", onDeviceReady(), false);
that worked for me!!