Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle Android Back Button on Phonegap InAppBrowser

I would like to disable or override the Android Back button while I am navigating pages on the InAppBrowser. Can I add an event listener that can handle that?

EDIT: Looking at the answer by @T_D below the solutions provided are the closest I could get to. It does not seem to be possible to override the button in InAppBrowser as all the PhoneGap tweaks stop working while navigating pages on this plugin. I was not able to find any other solution rather than modifying the API library. If there are any PhoneGap guys here and know something more, I 'll be glad to get some comment. Thanks.

The closest I got:

var ref = window.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener("backbutton", function () { })
like image 390
Dimosthenis Kontogiorgos Avatar asked May 15 '13 15:05

Dimosthenis Kontogiorgos


People also ask

What is InAppBrowser in Android?

The InAppBrowser is a web browser view that displays when calling [window. open](window. open. html)() , or when opening a link formed as <a target="_blank"> .

How do I close InAppBrowser?

There is no action to close the InAppBrowser. How can we achieve this? The user is redirected to an aws login page in the IAB and after suscessfull login the IAB should close and the user should be redirected to a screen in the app.


1 Answers

According to the documentation the behaviour of the hardware back button can be configured now for the InAppBrowser:

hardwareback: set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.

Thanks to Kris Erickson.

So just update your InAppBrowser plugin if the backward navigation is the desired behaviour.

For more details see: https://github.com/apache/cordova-plugin-inappbrowser/pull/86

like image 165
lhaferkamp Avatar answered Sep 28 '22 04:09

lhaferkamp