加载 Ionic / Cordova 应用程序外部的外部链接

External Links to load OUTSIDE of Ionic / Cordova app

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

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

对于外部链接,您必须使用 inAppbrowser Plugin.For 您在包含插件后才能在 phone 浏览器中打开的要求。使用代码

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.
*/

您必须安装以下插件

 > ionic plugin add cordova-plugin-inappbrowser

里面index.html

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

有关此插件的更多信息,请访问 plugin page

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

ionic plugin add cordova-plugin-whitelist

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

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

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

有关更多详细信息,请参阅 this article