David D. David D. - 1 year ago 180
Android Question

Disable hardware back button in Ionic application?

I'm trying to disable the back button on my Cordova app.
I'm using AngularJS + Ionic Framework.
I found topics about this and tried the code bellow, but it has absolutely no effect. Any idea?


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

Note that when I push back button, I have "hello" displayed in my console.

Answer Source

Finally found the answer on Ionic Forum thread:


$ionicPlatform.registerBackButtonAction(function () {
  if (condition) {
  } else {
    handle back action!
}, 100);

$ionicPlatform.registerBackButtonAction allows to completly overwrite back button behavior. First param is a callback function and the secondone a priority (only the callback with the highest priority gets executed).