# Not able to disable back press in ionic

**URL:** <https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113>\
**Category:** ionic-v1\
**Created:** [September 24, 2014, 2:56am UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113 "2014-09-24T02:56:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sukhdeep540](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@sukhdeep540](https://forum.ionicframework.com/u/sukhdeep540)\
**Post date:** [September 24, 2014, 2:56am UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113/1 "2014-09-24T02:56:24Z")

</div>

I am not able to disable the back press button.  
I am using the the code" onHardwareBackButton(callback) ".  
In callback function i am getting the alert successfully, but the back press will close the current page.  
Please help me, how can i disable the default functionality of the back press.

---

<div class="post-metadata">

**Author:** ![captain\_jim1](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@captain\_jim1](https://forum.ionicframework.com/u/captain_jim1)\
**Post date:** [September 24, 2014, 4:35am UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113/2 "2014-09-24T04:35:50Z")

</div>

I’m assuming you’re trying to disable the Android back button since you’re referencing a hardware back button. This is not an ionic topic, but at best a phonegap topic. Regardless, this should do it for you.

```
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
  e.preventDefault();
}
```

---

<div class="post-metadata">

**Author:** ![sukhdeep540](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@sukhdeep540](https://forum.ionicframework.com/u/sukhdeep540)\
**Post date:** [September 24, 2014, 3:09pm UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113/3 "2014-09-24T15:09:05Z")

</div>

Thanks for your help but the problem is still not solved.  
On back press “**onBackKeyDown(e)**” is called but still it exits the app.

---

<div class="post-metadata">

**Author:** ![Bonda](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonda/32/7841_2.png) [@Bonda](https://forum.ionicframework.com/u/Bonda)\
**Post date:** [September 24, 2014, 3:13pm UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113/4 "2014-09-24T15:13:38Z")

</div>

Try this code.  
I use it on various apps, and works as intented.

```
	//=================================================
	if(!$rootScope.$viewHistory.backView){
		$scope.backButton = $ionicPlatform.registerBackButtonAction( function () {
			$ionicViewService.nextViewOptions({ disableBack: true });
			$state.go('home');
		}, 105 );
		$scope.$on('$destroy', $scope.backButton);
	}
})

```

If the app has a view back, it does the back page event, else (to prevent exiting the app), redirects to home (there yo ucan just do a return false.  
The 105 stands for the priority of the events. There are various ionic events as close side menu, exit modal, etc. The 100 stands for back page or exit app.

---

<div class="post-metadata">

**Author:** ![shivamgupta2017](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@shivamgupta2017](https://forum.ionicframework.com/u/shivamgupta2017)\
**Post date:** [May 15, 2017, 1:23pm UTC](https://forum.ionicframework.com/t/not-able-to-disable-back-press-in-ionic/10113/5 "2017-05-15T13:23:08Z")

</div>

still not working please reply
