InAppBrowser Android Hardware back button unable to stop closing

Hi,

i need stop hardware back button, i tried in my application
const inAppBrowserOptions: InAppBrowserOptions = { hideurlbar: 'yes', hardwareback: 'no', closebuttoncaption: 'Close', zoom:'yes' }; this.inappBrowser = this.browser.create("http://localhost:9000/iframe.html", "_blank", inAppBrowserOptions);

the browser is opened successfully but when i pressed android hardware back button that InApp browser was closed, how to stop that.

1 Like

There is no way to stop that. Even if the option ‘harwareback’ is set to ‘no’, the inappbrowser will be closed when pressing the hardware back button if there is no previous page. So the only thing you can do to avoid this is, by reloading the same page after a 300ms or 500ms delay. If you try to reload the url in inappbrowser without any delay, the inappbrowser won’t be visible.
To do this, subscribe to the ‘exit’ event and reload the page with a delay when browser closes. Look at the following example,
browser.on('exit').subscribe(event => { console.log("exit event", event); if (url == "") { console.log("exit event url",url); reject("problem with back button..closed inappbrowser with back button"); } });
Here I did it with an if condition to ensure that the inappbrowser is closing without redirecting to my desired url. The ‘url’ here is just a local variable to implement my logic.