I'm using the cordova InAppBrowser to display content from an external site in my app. When I open the browser on an iPhone, there are some buttons at the bottom of the InAppBrowser for closing it or navigating back and forth. The InAppBrowser on an Android device has no such buttons and has no obvious way for the user to close the browser.
I know how to programmatically close the InAppBrowser, but how can the user close it when using an Android device?
I know the user can hit the hardware back button to close the browser, but (1) that's not intuitive - the back button typically means "go back a page", and (2) I'd eventually like to change the behavior of the back button to go back a page within the site that is displaying inside the InAppBrowser, rather than close the browser.
I'm using the cordova InAppBrowser to display content from an external site in my app. When I open the browser on an iPhone, there are some buttons at the bottom of the InAppBrowser for closing it or navigating back and forth. The InAppBrowser on an Android device has no such buttons and has no obvious way for the user to close the browser.
window.open = cordova.InAppBrowser.open; If you change the browsers window.open function this way, it can have unintended side effects (especially if this plugin is included only as a dependency of another plugin). The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.
By using the InAppBrowser, we can open an external link from the Cordova application. It can easily load a webpage inside the Cordova app. In a simple language, we can say that this plugin loads a child browser in your Cordova app and loads a web page or third party (untrusted) content.
If you want all page loads in your app to go through the InAppBrowser, you can simply hook window.open during initialization. For example: Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. ref: Reference to the InAppBrowser window when the target is set to '_blank'.
For those of us using Ionic (ionicframework.com) and/or ngcordova (ngcordova.com). The following code will launch the inappbrowser and then close the dialog via a link <a href="/mobile/close">close</a>
.
$cordovaInAppBrowser.open('http://localhost:3000/#/mypath/', '_blank', options).then((event) ->
# success
return
).catch (event) ->
# error
return
$rootScope.$on '$cordovaInAppBrowser:loadstart', (e, event) ->
$log.log 'loadstart', e, event
if event.url.match('mobile/close')
$cordovaInAppBrowser.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With