8

I'm working on a Ionic / Cordova app where I load feeds and news that sometimes contain external links. I need to load those external links outside of the app, not in the InAppBrowser but in the phone browser.

Is it possible to do this as a default behavior on all links?

Francesco Fiori
  • 183
  • 2
  • 7

3 Answers3

7

In order to open URL using the corresponding system application you need the whitelist plugin. If your project is based on the scaffolded demo program, it should already be installed. If not (or simply to ensure that) :

ionic plugin add cordova-plugin-whitelist

Once the plug-in is installed, you will have to specify the intend you want to open from your application. In your config.xml, add:

<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
...

Given the above rules, all URI stating with one of the specified protocols (http, https, tel, sms, mailto, ...) will be open using the corresponding system application. Of course, you can be much more specific by replacing the * wildcards by actual values.

See this article for additional details.

Community
  • 1
  • 1
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
  • Thank you, that is perfectly what I needed for opening a external URL with the system browser without additional plugin. – keupsonite Jun 27 '16 at 13:13
  • There's no single answer as of today on the topic which could be as simple as this answer is. – kumar Nov 18 '16 at 11:55
2

For external links you have to use the inAppbrowser Plugin.For your reqiurment after including the plugin to open in phone browser. use the code

var ref = window.open('http://apache.org', '_system', 'location=yes');

/*
_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.
*/
Banik
  • 911
  • 6
  • 10
  • thanks but my links are embedded in the feeds I load with the app, I need a filter or something to transform every link in a window.open('http://apache.org', '_system', 'location=yes'); – Francesco Fiori Apr 03 '15 at 12:51
  • I had a problem where this didn't work - it was because i had removed "cordova.js" white testing in the browser :i.... Don't do the same mistake guys :) – Thylle Jan 25 '17 at 10:21
2

You have to install following plugin

 > ionic plugin add cordova-plugin-inappbrowser

Inside index.html

<div class="list">
    <a class="item" href="#" onclick="window.open('http://google.com', '_system', 'location=yes'); return false;">
       Open Browser
    </a>    
</div>

For more info about this plugin visit the plugin page.

Anil Singh
  • 4,293
  • 2
  • 24
  • 19