Andresson
Andresson

Reputation: 13

Phonegap 3.2 backbutton override

SO now with Phonegap 3.2 there is no need to override the backbutton to leave the app.

But i want to leave the app when im in the home page. The user can navigate endless throught the app and go back the same number of times to leave the app.

IM trying to override like before phonegap 3.2:

function onDeviceReady() {
    document.addEventListener("backbutton", onBackKeyDown, false); 
}

 var onBackKeyDown = function() {

 if($.mobile.activePage.is("#home")) {

         navigator.app.exitApp();
         analytics.Stop();
           } 
  else {
         navigator.application.backHistory();
        }
}

I always get $.mobile.activePage null, so i dont find the way to figure out in one page i am.

Im trying with some event... but phonegap doesnt specify what events trigger backbutton.

Upvotes: 0

Views: 109

Answers (1)

Divesh Salian
Divesh Salian

Reputation: 1455

I have modified your code bit.... Here is the demo for active page

function onDeviceReady() {
      document.addEventListener("backbutton", onBackKeyDown, false); 
}

var onBackKeyDown = function() {

var activePage = "page1"
if($.mobile.activePage[0].id=="page1") {

     navigator.app.exitApp();
     analytics.Stop();
       } 
else {
     navigator.application.backHistory();
    }
}

Upvotes: 1

Related Questions