外部链接加载Ionic/Cordova app的OUTSIDE

Fra*_*ori 7 cordova ionic-framework

我正在开发一个Ionic/Cordova应用程序,我在其中加载有时包含外部链接的提要和新闻.我需要在应用程序外部加载那些外部链接,而不是在InAppBrowser中,而是在手机浏览器中.

是否可以将此作为所有链接上的默认行为?

Syl*_*oux 6

要使用相应的系统应用程序打开URL,您需要白名单插件.如果您的项目基于脚手架演示程序,则应该已经安装了它.如果不是(或只是为了确保):

ionic plugin add cordova-plugin-whitelist
Run Code Online (Sandbox Code Playgroud)

安装插件后,您必须指定要从应用程序打开的打算.在config.xml中,添加:

<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
...
Run Code Online (Sandbox Code Playgroud)

根据上述规则,将使用相应的系统应用程序打开所有使用指定协议之一(http,https,tel,sms,mailto,...)的URI.当然,通过用*实际值替换通配符可以更加具体.

有关其他详细信息,请参阅此文


小智 2

对于外部链接,您必须使用inAppbrowser插件。根据您的要求,包含要在手机浏览器中打开的插件后。使用代码

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.
*/
Run Code Online (Sandbox Code Playgroud)