在 Safari (cordova) 中打开外部链接 [英] Open an external link in Safari (cordova)

查看:33
本文介绍了在 Safari (cordova) 中打开外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中打开一个外部 url 链接,这是一个cordova 应用程序.现在它使用模态视图呈现应用程序内浏览器,但它没有后退按钮或关闭按钮.用户在单击外部链接时基本上会卡住.例如,当有人单击包含在访问网站"中的此链接时,会显示应用内浏览器,网站显示正常,但无法导航回应用或关闭应用内浏览器.我该如何解决这个问题?

I am trying to open an external url link in my app which is a cordova app. Right now its presents an in app browser using modal view but it has NO back button or close button. The user essentially gets stuck when they click an external link. For instance, when someone clicks this link, enclosed in "Visit Website", an in app browser shows up, the website shows up fine, BUT there is no way to navigate back to the app, or close the in app browser. How do I go about fixing this?

<a href="http://www.sdtaproom.com/" target="_blank">Visit Website</a>

我看到有一个解决方案,window.open("http://stackoverflow.com", "_system");,但是我不知道如何在 href 代码中实现它.

I saw that there is a solution, window.open("http://stackoverflow.com", "_system");, but I don't know how to implement it in the href code.

ANSWER(已编辑):将此代码添加到头部的脚本标记中.

ANSWER (Edited): Add this code in the script tag in the head.

<script src="cordova.js"></script>
<script type="text/javascript">
window.addEventListener('load', function () {
  $(document).on('click', 'a[target="_system"],a[target="_blank"]', function (e) {
    e.preventDefault();
    var url = this.href;
    window.open(url,"_system");
  });
}, false);
</script>

推荐答案

您可以在 href 属性中嵌入 javascript 代码.这应该可以解决问题:

You can embed javascript code in the href attribute. This should do the trick:

<a href="javascript: window.open('http://www.sdtaproom.com/', '_system'); return false;">Visit Website</a>

您还必须安装 InAppBrowser 插件(不要被它的名字所迷惑).

You will also have to install the InAppBrowser plugin (don't be fooled by its name).

这篇关于在 Safari (cordova) 中打开外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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