在Safari中打开一个外部链接(科尔多瓦) [英] Open an external link in Safari (cordova)

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

问题描述

我试图打开我的应用程序的外部URL链接这是科尔多瓦的应用程序。现在它的$ P $在应用程序浏览器中使用模式视图psents的,但它没有后退按钮或关闭按钮。用户当他们点击外部链接基本上卡住。例如,当有人点击这个链接,包含在访问网站,应用内浏览器中显示,该网站显示罚款,但没有办法导航回应用程序,或关闭应用程序中的浏览器。我该如何去修复呢?

 < A HREF =htt​​p://www.sdtaproom.com/目标=_空白>访问网站< / A>

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

ANSWER(编辑):添加此code在头部的脚本标签

 <脚本SRC =cordova.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
window.addEventListener('负荷',函数(){
  $(文件)。在('点击','一[目标=_系统],一个[目标=_空白],功能(E){
    亦即preventDefault();
    VAR URL = this.href;
    window.open(URL,_系统);
  });
},FALSE);
< / SCRIPT>


解决方案

您可以嵌入在的href 属性的JavaScript code。这应该做的伎俩:

 < A HREF =JavaScript的:window.open('http://www.sdtaproom.com/','_system');返回false;>访问网站&LT ; / A>

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

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>

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 (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>

解决方案

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>

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

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

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