6

We want every link on the app to be able to be opened in the external browser on the system, with the exception of a selection of hostnames.

We tried putting <allow-navigation href="*.hostname.com/*"/> , but this gets overridden when you use <allow-intent href="http://*/*" /> and <allow-intent href="https://*/*" as the intent tags for all the other links in the app.

The expected result would be our hostnames being opened within the app, but they open on the external browser instead.

I've tried looking at all the recent documentation and help available on the net, but could not find an answer to my solution. Hope you guys know.

Edit: forgot to mention we run the latest cordova CLI and the latest whitelist plugin with the inappbrowser plugin.

Sincerely,

Daniel

Thrinaria
  • 61
  • 1
  • 4
  • where do you see this issue? on iOS? android? both? On cordova-ios 4.1.1 this should be fixed – jcesarmobile May 16 '16 at 07:48
  • @Thrinaria suggest you to have a look at this link - http://stackoverflow.com/questions/37127660/cordova-wrapper-app-where-internal-links-load-in-app-external-links-load-in-bro who dealt a similar issue – Gandhi May 16 '16 at 11:19
  • @jcesarmobile 6.1 both android and ios. – Thrinaria May 16 '16 at 23:09
  • @Gandhi Yea I've seen this, and tried this, but it still got overridden. – Thrinaria May 16 '16 at 23:10
  • I was wrong, it wasn't fixed on cordova-ios 4.1.1, it was fixed on 4.2.0. See my answer on http://stackoverflow.com/questions/37866341/cordova-internal-hyperlinks-always-open-in-safari/38008662#38008662 – jcesarmobile Jun 26 '16 at 18:11
  • solved? how do you achieve this?some abc.example.com to be navigated within the webview and xyz.example.com in external browser! – NitZRobotKoder Apr 03 '17 at 13:37

2 Answers2

1

Try changing your <allow-*> tags to this:

<allow-intent href="*.hostname.com/*"
<allow-navigation href="https://*/*"
<allow-navigation href="http://*/*"
<allow-access href="https://*/*"
<allow-access href="http://*/*"

The <allow-navigation> tag is for controlling urls the Cordova webview itself can be navigated to.

Look at this article for a better understanding on Cordova's Whitelist.

johnborges
  • 2,422
  • 20
  • 33
0

I think you need to do it manually. You can use inApp Browser plugin to achieve this.

  1. Check the link is internal/external (By checking the hyperlink contains your hostname contains or not)
  2. If it is external call the system's browser and open the link cordova.InAppBrowser.open('http://external-domain.name', '_system', 'location=yes');
  3. If it is internal open the link inside InAppBrowser cordova.InAppBrowser.open('http://yourdomain.name', '_blank', 'location=yes');

You can ignore 3rd step if you don't need it.

Full code:

$(document).on("click","a",function(e){        
      var hrefs = $(this).attr("href");        

      if(hrefs.indexOf("yourdomain") > -1) {
          //Open link inside inAppBrowser   
          cordova.InAppBrowser.open(hrefs, '_blank', 'location=yes');
          e.preventDefault();//To prevent default click
       } 
      else {
           //Open link inside system browser
           cordova.InAppBrowser.open(hrefs, '_system', 'location=yes');
           e.preventDefault();//To prevent default click
       }
})
Avijit
  • 1,253
  • 13
  • 21