Apache Cordova allow-navigation overridden by allow-intent
Asked Answered
H

2

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

Hibernicism answered 10/5, 2016 at 13:17 Comment(6)
where do you see this issue? on iOS? android? both? On cordova-ios 4.1.1 this should be fixedLawful
@Hibernicism suggest you to have a look at this link - #37128160 who dealt a similar issueCatbird
@Lawful 6.1 both android and ios.Hibernicism
@Catbird Yea I've seen this, and tried this, but it still got overridden.Hibernicism
I was wrong, it wasn't fixed on cordova-ios 4.1.1, it was fixed on 4.2.0. See my answer on #37866841Lawful
solved? how do you achieve this?some abc.example.com to be navigated within the webview and xyz.example.com in external browser!Treva
N
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.

Neddy answered 17/5, 2016 at 15:14 Comment(1)
allow-access should just be i.e. <access origin="*" />Bedevil
C
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
       }
})
Crescentia answered 15/5, 2016 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.