1

I am trying to stop my application from returning to the previous screen when a modal is present. This currently closes the modal but also exits the existing page and returns home.

Any ideas on how to stop this from happening ?

document.addEventListener('backbutton', function(e) {
  if(modalIsOpen === true) {
    e.preventDefault();
    setIsOpen(false);
  }
});
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Ndango
  • 59
  • 8
  • You might be looking for the `onunload` or `onbeforeunload` .. possible duplicate : https://stackoverflow.com/questions/821011/prevent-a-webpage-from-navigating-away-using-javascript – Deepak Kamat Oct 31 '21 at 06:43
  • Still trying to figure it out currently just using the code I originally used but it doesn't function like I would have wanted. – Ndango Nov 06 '21 at 12:02

1 Answers1

0

This is the solution I found with help from Ionic

document.addEventListener('ionBackButton', (ev) => {
            ev.detail.register(10, (processNextHandler) => {
                if (modalIsOpen === true) {
                    setIsOpen(false);
                    console.log('Handler was called!');
                    processNextHandler();
                }
            });
    });
Ndango
  • 59
  • 8