I am using phonegapand i am registering backbutton onDeviceReady
Function but getting function called when clicked on device's back button. and i have added
<script src="lib/cordova-2.6.0.js"></script>
document.addEventListener("backbutton", onBackClickEvent, false);
function onBackClickEvent() {
alert("back onBackClickEvent");
}
This onBackClickEvent()
function is not getting called, I've never seen that alert poped up. I am also getting an error of Uncaught ReferenceError: cordova is not defined
what could be the error Please suggest me. Thanks in advance.
Don't forget to call the "deviceready" event.
From phonegap doc :
This is a very important event that every Cordova application should use.
Cordova consists of two code bases: native and JavaScript. While the native code is loading, a custom loading image is displayed. However, JavaScript is only loaded once the DOM loads. This means your web application could, potentially, call a Cordova JavaScript function before it is loaded.
The Cordova deviceready event fires once Cordova has fully loaded. After the device has fired, you can safely make calls to Cordova function.
Try this
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
document.addEventListener("backbutton", onBackClickEvent, false);
}
function onBackClickEvent()
{
alert("back onBackClickEvent");
}
I got the answer to my Question. I was struggling and many developers tries to resolve it and when i found the silly mistake i found myself so silly.
I was writing
document.addEventListener("deviceready", onDeviceReady(), false);
instead of
document.addEventListener("deviceready", onDeviceReady, false);
thats why i am getting an error cordova is not defined and no other listeners are getting registered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With