user2570135
user2570135

Reputation: 3009

How to override the back button in cordova

I am working on upgrading my MFP app from 7.1 to 8.0 and one of issue identified by the migrate script is that thewindow.WL.App.overrideBackButton(_deviceBackButtonHandler) API is discontinue and I have to used Cordova inappbrowser

However, I don't see a method in the Cordova Plugin class to do this action

Here is my code in MFP 7.1

if ($rootScope.android) {
          console.log('installing custom back button handling to MFP');
          window.WL.App.overrideBackButton(_deviceBackButtonHandler);
        }



function _deviceBackButtonHandler() {
      if ($rootScope.cancelOverlayFunction) {
        $rootScope.cancelOverlayFunction();
        if (!$rootScope.$$phase) {
          $rootScope.$apply();
        }
      } else if (history.length > 1) {
        $rootScope.back();
      }
      // TODO: we're at the beginning of time, add else block to invoke the OS back button behavior
    } 

Can you please give some hints on how to rewrite the call .

Thanks for your help

Upvotes: 0

Views: 434

Answers (1)

Idan Adar
Idan Adar

Reputation: 44526

Did you search the Cordova documentation? For example, here: http://cordova.apache.org/docs/en/6.x/cordova/events/events.html#backbutton

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
    // Handle the back button
}

Upvotes: 3

Related Questions