Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the cordova InAppBrowser to provide a way for the user to close the browser when using an Android device?

Tags:

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.

like image 505
Troy Avatar asked Mar 11 '13 21:03

Troy


People also ask

How to close the InAppBrowser on Android?

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.

How do I open Cordova in InAppBrowser?

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.

How to open an external link from Cordova app?

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.

How to make the InAppBrowser open all pages in the app?

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'.


1 Answers

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()
like image 94
Stone Avatar answered Sep 18 '22 16:09

Stone