使用Cordova从Android打开外部浏览器中的链接 [英] Open link in external browser from Android with cordova

查看:608
本文介绍了使用Cordova从Android打开外部浏览器中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在本机浏览器或其他外部浏览器中通过我的应用程序打开一个链接,但只能通过它打开应用程序内浏览器.

I am trying to open a link in the native browser or other external browser from my app, but I can only get it to open an in app browser.

我已按照此处指定的方式安装了内置浏览器:

I have the inappbrowser installed as specified here:

cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#window.open

cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#window.open

我这样称呼浏览器窗口: window.open(" http://yourmindandmedia.com ",'_system');

I call the browser window like this: window.open("http://yourmindandmedia.com", '_system');

结果与我执行此操作的结果相同: window.open(" http://yourmindandmedia.com ",'_blank');

the result is the same as if I do this: window.open("http://yourmindandmedia.com", '_blank');

当我按下设备后退按钮时,我的应用程序全部被洗净,不显示任何图形且不支持任何事件.我也尝试过:

When I hit the device back button, my app is all washed out displaying no graphics and supporting no events. I've tried this as well:

navigator.app.loadUrl("yourmindandmedia.com",{openExternal:true));

navigator.app.loadUrl("yourmindandmedia.com", { openExternal:true });

获得相同的结果.

这些示例在Android环境中完成,但我也将在iOS中实现.理想情况下,解决方案是相同的.

These examples are done in Android environment, but I will be implementing in iOS as well. Ideally, the solutions are identical.

谢谢.

推荐答案

这是我使用的代码,直到cordova像以前一样工作. 如您所见,这是您已经尝试过的方法. 尝试按cordova plugin -l键,以确保您有内置浏览器. 我是通过cordova plugin add org.apache.cordova.inappbrowser安装的,它与以前的说明有所不同.我使用的是Cordova V3.2.

Here's the code I'm using until cordova works as before. As you can see it's a method you already tried. Try cordova plugin -l to make sure you've got the inappbrowser. I installed via: cordova plugin add org.apache.cordova.inappbrowser which is a bit different than the older instructions.I'm using Cordova V3.2 .

 window.onclick = clickEvent;

function clickEvent(e){
    e = e || window.event;
    var t = e.target || e.srcElement
    if ( t.name || t.href ){
       if( typeof t.href == "string" && t.href.substr(0,4) == 'http' ){
           if( t.attributes.href.value !== "#" ){
               window.open(t.href, '_system', 'location=yes');
           }
           return false; // no further action for this click
       }
    }
    return true; // process click as normal
}

我最初有navigator.app.loadUrl(),但它似乎特定于Android.

I originally had navigator.app.loadUrl() but it seems to be specific to Android.

这篇关于使用Cordova从Android打开外部浏览器中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆