Apache Cordova allows navigation overridden by permission

We want every link in the application to be open in an external browser on the system, with the exception of choosing host names.

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

The expected result will be that our host names will open in the application, but they will open in an external browser.

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

Edit: forgot to mention that we are launching the latest version of the CLI cordons and the latest plugin with whitelist with the inappbrowser plugin.

Yours faithfully,

Daniel

+5
source share
2 answers

Try changing the <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> is for managing the URLs to which the Cordova website itself can be moved.

Take a look at this article for a better understanding of Cordoba's whitelist.

+1
source

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

  • Check that the link is internal / external (by checking the hyperlink contains your hostname or not)
  • If this is an external call to the system browser and open the link cordova.InAppBrowser.open('http://external-domain.name', '_system', 'location=yes');
  • If he internally opens the link inside InAppBrowser cordova.InAppBrowser.open('http://yourdomain.name', '_blank', 'location=yes');

You can ignore the third step if you do not 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 } }) 
0
source

All Articles