Backgutton in phonegap not registering and not working properly

I use phonegapand, I register the onDeviceReady function, but I get the function onDeviceReady when the device return button is clicked. and I 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 called, I have never seen this warning appear. I also get the error "Failure ReferenceError: cordova" is undefined

What could be a mistake. Please suggest me. Thanks in advance.

+6
source share
5 answers

I got an answer to my question. I struggled, and many developers are trying to solve it, and when I found a stupid mistake, I was so stupid.

I wrote

 document.addEventListener("deviceready", onDeviceReady(), false); 

instead

 document.addEventListener("deviceready", onDeviceReady, false); 

This is why I get an error message. Cordoba is undefined and no other listeners register.

+4
source

Remember to trigger the deviceready event.

From the phone book doc:

This is a very important event that every Cordoba application should use.

Cordoba consists of two code bases: native and JavaScript. At that time, native code is loaded, a custom boot image is displayed. However, JavaScript only loads after loading the DOM. This means that your network application can potentially call the Cordoba JavaScript function before downloading.

The Cordova deviceready event fires as soon as Cordoba is fully loaded. After the device has quit, you can safely call the Cordoba function.

try it

 document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("backbutton", onBackClickEvent, false); } function onBackClickEvent() { alert("back onBackClickEvent"); } 
+5
source

I encountered this error after upgrading to cordon 3.1. It turns out that this should be explicitly added in the config.xml 3. * phonebook and beyond.

 <feature name="App"> <param name="android-package" value="org.apache.cordova.App" /> </feature> 

See link

+4
source

For the back button, I use this

 //Android back button handler methods $(document).ready(function() { document.addEventListener("deviceready", setOverrideBackbutton, false); }); /** * Allow override of the back button on Android platforms */ function setOverrideBackbutton() { if (typeof device != "undefined" && device.platform == "Android") { navigator.app.overrideBackbutton(true); } document.addEventListener("backbutton", backButtonTap, true); } /** * Callback after a backbutton tap on Android and windows platforms. * Do nothing. */ function backButtonTap() { //Do not remove } 
+3
source

pls check the correct path and file name on your cordova.js. make sure you check the real cordova.jar file and the Android private personal files in the project property-> Java Build Path-> Order and Export.

For more information check this link.

and if you import several files, then put the cordova.js file in front of the other.js file and it should work.

and just use

 <script src="cordova-2.6.0.js"></script> 

instead

also check link1 and link2

+1
source

Source: https://habr.com/ru/post/947270/


All Articles