2015-04-03 70 views
6

我正在处理一个Ionic/Cordova应用程序,我在其中加载包含外部链接的提要和新闻。我需要在应用程序之外加载这些外部链接,而不是在InAppBrowser中,但在手机浏览器中。加载外部Ionic /科尔多瓦应用程序的外部链接

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

+0

你到目前为止尝试过什么?你能编辑你的问题并提供一些代码吗? – 2015-04-03 11:01:57

+0

我通常使用window.open和targer系统打开外部链接,在这种情况下,我需要在Feed中嵌入的每个链接上动态加载 – 2015-04-03 12:53:46

回答

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

谢谢,但是我的链接已嵌入到应用中加载的Feed中,我需要('http://apache.org','_system','location = yes');一个过滤器或其他东西来转换window.open中的每个链接。 – 2015-04-03 12:51:23

+0

我有一个问题,这不起作用 - 这是因为我已经删除了“cordova.js”在浏览器中的白色测试:我....不要做同样的错误家伙:) – Thylle 2017-01-25 10:21:57

2

您有以下插件

> 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更多信息。

5

要使用相应的系统应用程序打开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:*" /> 
... 

鉴于上述规则,所有的URI与指定协议的一个声明(HTTP,HTTPS,电话,短信,邮寄地址,...)将使用相应的开放系统应用。当然,通过用实际值替换*通配符可以更具体。

有关其他详细信息,请参阅this article

+0

谢谢,这是完全是我需要用系统浏览器打开外部URL而无需额外的插件。 – keupsonite 2016-06-27 13:13:43

+0

截至今天,关于这个话题的答案可能与这个答案一样简单。 – kumar 2016-11-18 11:55:00

相关问题