TIP: You can only test all samples with the APK APP installed on your phone. The Tester app doesn't work in this case.
Samples above "run" but none of them prevented the back action in my tests.
I found the following sample that worked fine for me.
It will block back button on all pages
pre
var $ionicPlatform = Apperyio.get("$ionicPlatform");
$ionicPlatform.registerBackButtonAction(function(event) {
Code: Select all
alert("Back Button was pushed"); // alert message just to test it
}, 100);
/pre
Also, the following version prompt an exit question in a specific page. I implemented this to prevent users to go back to Login logon page:
pre
var $ionicPlatform = Apperyio.get("$ionicPlatform");
var $ionicPopup = Apperyio.get("$ionicPopup");
$ionicPlatform.registerBackButtonAction(function(event) {
if ($scope.header.title == "Main Page") { // In this condition user is prompted to exit app
$ionicPopup.confirm({
title: 'System warning',
template: 'are you sure you want to exit?'
}).then(function(res) {
if (res) {
ionic.Platform.exitApp();
}
});
} else {
history.back(); //this will force to continue to previous page
}
}, 100);
/pre
Reference: http://www.gajotres.net/ionic-framewo...
More here: http://ionicframework.com/docs/api/se...
No further assistance is required for me.