繁体   English   中英

PhoneGap Build:如何在Android设备浏览器中打开外部URL?

[英]PhoneGap Build: how to open external url in device browser on Android?

外部URL不会在我的PhoneGap Android应用程序的系统浏览器中打开。 我正在使用PhoneGap Build 2.3.0。

根据Cordova文档,我使用了目标'_system':

window.open('http://www.myurl.nl', '_system');

在我的config.xml中,我有:

<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
<access origin="*" browserOnly="true" />

但仍然在我的应用程序webview中打开链接。

怎么解决这个?

当你想继续使用PhoneGap Build时,这不是答案,但我通过在我的机器上为Cordova(PhoneGap)设置开发环境并在本地编译应用程序来解决问题。 在Cordova 2.5.0 window.open('http://www.myurl.nl', '_system'); 工作完美,它将打开系统浏览器中的链接。

所以我的建议是停止使用PhoneGap Build并开始在本地编译你的应用程序。 以下是如何为Cordova >>设置开发环境

迟到的答案,但可能会有所帮助。

navigator.app.loadUrl('https://google.com/', { openExternal:true });

科尔多瓦3.3.1

这个问题现在有点老了,但我觉得值得更新。 当与2.9.0一起使用时,现在可以正常使用PhoneGap Build。

我已经在Android 4.3和iOS 6.1.3上编译和测试了它。 我的应用程序中没有InAppBrowser插件,因为打开应用程序中的页面,而不是让本机浏览器打开它们,我只有以下访问标记:

<access origin="http://127.0.0.1*"/>
<access origin="http://phonegap.com" subdomains="true" />

这对我有用。 Phonegap 3.1.0。

HTML代码:

<a id="ext-link" href="#">Google it</a>

要么

<button id="ext-link" href="#">Google it</button>

Javascript(使用jQuery + cordova):

$("#ext-link").on("click"), function() {
    if (typeof navigator !== "undefined" && navigator.app) {
        // Mobile device.
        navigator.app.loadUrl('http://www.google.com/', {openExternal: true});
    } else {
        // Possible web browser
        window.open("http://www.google.com/", "_blank");
    }
});

希望有所帮助。

@George Siggouroglou:对于最终会在文档中出现多次的元素使用id并不是一个好主意。 相反,它的优良做法是使代码更加模块化。

如果期待触摸设备,在“点击”之前使用“点击”也是一个不错的选择,因为它比点击更快更快。 检查触摸能力的东西,我更喜欢使用modernizr,因为它使功能检测变得轻而易举。

jQuery Mobile点击事件在单个目标对象上发生的快速,完整的触摸事件后触发。 它是由触摸手势的释放状态触发的等效于标准点击事件的手势。 https://api.jquerymobile.com/tap/

希望有人帮助

**html code:**

<a class="ext-link" href="#">Google it</a>

要么

<button class="ext-link" href="#">Google it</button>

Javascript(使用jQuery):

//define tap or click event type on root level (can be combined with modernizr)
iaEvent = "click";
if (typeof navigator !== "undefined" && navigator.app) {
   iaEvent = "tap";
}
$('.ext-link').each.bind(iaEvent, function() {
    if (typeof navigator !== "undefined" && navigator.app) {
        // Mobile device.
        var linktarget = this.attr("href");
        navigator.app.loadUrl(linktarget, {openExternal: true});
    } else {
        // Possible web browser
        window.open(linktarget, "_blank");
    }
});

用这个

window.open('http://www.myurl.nl', '_blank', 'location=yes');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM