jquery - Back button in Android App not working to exit the application -



jquery - Back button in Android App not working to exit the application -

i using cordova version 3.6 create first mobile application. want utilize button of device exit application when reached home page. went through next resources not able accomplish purpose.

http://cordova.apache.org/docs/en/3.6.0/cordova_events_events.md.html#backbutton

phonegap - android exit on backbutton

backbutton confirm exit app android + phonegap + jquery

my code:

js:

function onload() { document.addeventlistener("deviceready", ondeviceready, false); } function ondeviceready() { // register event listener document.addeventlistener("backbutton", onbackkeydown, false); } function onbackkeydown() { document.addeventlistener("backbutton", function(e){ if($('body').is('#main')){ //main home page id.. e.preventdefault(); navigator.app.exitapp(); } else { navigator.app.backhistory() } }, false); }

html:

thanks time , efforts.

adding listener backbutton 1 time again in event handler doesn't create much sense. remove document.addeventlistener onbackkeydown(). , pass event function.

function onbackkeydown(e) { if($('body').is('#main')){ //main home page id.. e.preventdefault(); navigator.app.exitapp(); } else { navigator.app.backhistory() } }

android jquery cordova

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -