如何在科尔多瓦的应用内浏览器中的内容中打开系统浏览器中的链接? [英] How do I open a link in the system browser from content in an in app browser in cordova?

查看:120
本文介绍了如何在科尔多瓦的应用内浏览器中的内容中打开系统浏览器中的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多关于如何通过cordova应用程序的主要html / js代码中的内容来做到这一点的例子,



例如:

  window.open(url,_system); 

,但是当链接位于应用内浏览器中的内容时,它似乎不起作用



任何想法如何实现这一点?



感谢

解决方案

这还不够,我想你缺少下面的步骤1。这里是我使用的步骤,以使它工作很好:


  1. 确保您有外部网站的访问标记在 config.xml 中,如下所示(显然用与您的网站匹配的 * google * )。



    < access origin =* google。*launch-external =yes/>

    / li>
  2. 将类添加到要以此方式工作的所有链接。我使用外部类名


  3. 向文档添加以下委派的事件处理程序jQuery)



    jQuery(document).delegate('。external','click',function(e){
    window。 open(e.target.href,'_system');
    e.preventDefault();
    });


e.preventDefault()对于确保浏览器不会尝试处理点击本身很重要。



现在它应该可以工作了


I've seen plenty of examples of how to do this from content in the main html/js code of the cordova app,

for example:

window.open(url, "_system");

but it doesn't seem to work when the link is in the content already in an in app browser.

Any ideas how I could achieve this?

Thanks

解决方案

That is not quite enough, I think you are missing step 1 below. Here are the steps I am using to get this to work well:

  1. Make sure you have an access tag for the external site in your config.xml as follows (obviously replacing *google* with whatever matched your site).

    <access origin="*google.*" launch-external="yes" />

  2. Add a class to all the links you want to work this way. I use the external class name

  3. Add the following delegated event handler to your document (this example uses jQuery)

    jQuery(document).delegate('.external', 'click', function (e) { window.open(e.target.href, '_system'); e.preventDefault(); });

The e.preventDefault() is important to ensure the browser does not try to handle the click itself

Now it should work

这篇关于如何在科尔多瓦的应用内浏览器中的内容中打开系统浏览器中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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