# Back Button Hardware Event Handler Can't Determine Overlay View

**URL:** <https://forum.ionicframework.com/t/back-button-hardware-event-handler-cant-determine-overlay-view/178866>\
**Category:** ionic-v3\
**Created:** [December 3, 2019, 5:41am UTC](https://forum.ionicframework.com/t/back-button-hardware-event-handler-cant-determine-overlay-view/178866 "2019-12-03T05:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![OliverPrimo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/oliverprimo/32/121442_2.png) [@OliverPrimo](https://forum.ionicframework.com/u/OliverPrimo)\
**Post date:** [December 3, 2019, 5:41am UTC](https://forum.ionicframework.com/t/back-button-hardware-event-handler-cant-determine-overlay-view/178866/1 "2019-12-03T05:41:02Z")

</div>

Hello Everyone,

I modified the functionality of hardware back button. It works on pages but it cannot determine whether an overlay views like modals and alert dialog boxes are present or not.

**Here is my code**

```auto
    this.platform.registerBackButtonAction(() => { 
      let nav = app._appRoot._getActivePortal() || app.getActiveNav();
      let activeView = nav.getActive().instance;

      if (activeView != null) {
        if (nav.canGoBack()) {
            if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
                // do something
            } else {
	           nav.pop();
            }
        } else if (activeView.isOverlay) {
          activeView.dismiss();
        } else {
          let alert = this.alertCtrl.create({
            title: 'Ionic App',
            message: 'Do you want to close the app?',
            buttons: [{
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
                console.log('Application exit prevented!');
              }
            },
            {
              text: 'Close',
              handler: () => {
                this.platform.exitApp();
              }
            }]
          });
          alert.present();
        }
      }
    });

```

I hope someone can help me with this 🙂

---

<div class="post-metadata">

**Author:** ![OliverPrimo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/oliverprimo/32/121442_2.png) [@OliverPrimo](https://forum.ionicframework.com/u/OliverPrimo)\
**Post date:** [December 6, 2019, 5:25am UTC](https://forum.ionicframework.com/t/back-button-hardware-event-handler-cant-determine-overlay-view/178866/2 "2019-12-06T05:25:14Z")

</div>

Please anyone help me 😢 😢. I’ve been stuck on this for a week now.
