Disable hardware back button in Ionic application?

后端 未结 8 1029
暗喜
暗喜 2020-12-24 13:21

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

8条回答
  •  别那么骄傲
    2020-12-24 14:08

    To prevent App from device back button functionality use,

          $ionicPlatform.registerBackButtonAction(function (event) {
               event.preventDefault();
          }, 100);
    

    If you want to prevent the particular page use,

           $ionicPlatform.registerBackButtonAction(function (event) {
               event.preventDefault();
               if ($location.path() === "/pagename" || $location.path() === "pagename") {
                 navigator.app.exitApp();
               } else {
                 $ionicHistory.goBack();
               }
            }, 100);
    

提交回复
热议问题