简体   繁体   English

HTML5 phonegap webapp在safari或其他原生应用中打开链接

[英]HTML5 phonegap webapp open links in safari or other native app

I have a working, accepted and approved by apple, html5 phonegap webapp but I cannot get external links to open safari or the maps apps. 我有一个工作,接受和批准的苹果,html5 phonegap webapp但我无法获得外部链接打开safari或地图应用程序。 The problem is the same on the android version. Android版本的问题是一样的。

What happens is that when the link is clicked/tapped, I am guessing, the phonegap inappbrowser grabs the window.open event and loads the external page into the current window instance and there is no back key. 发生的事情是,当点击/点击链接时,我猜,phonegap inappbrowser抓取window.open事件并将外部页面加载到当前窗口实例中,并且没有后退键。

The App will now simply just show the external loaded page until it is exited and restarted. 该应用程序现在只是显示外部加载的页面,直到它退出并重新启动。

I have read huge amounts of comments and forums about this. 我已经阅读了大量关于此的评论和论坛。 I have followed all the options I could find yet still the issue persists. 我已经遵循了我能找到的所有选项,但问题仍然存在。

Could someone please tell me where I am going wrong as I am losing hair at an alarming rate... 有人可以告诉我我哪里出错了,因为我正以惊人的速度失去头发......

Build is online with Phonegap 3.1 using phonegap.js and jquery. 使用phonegap.js和jquery使用Phonegap 3.1在线构建。 I am capturing the external link through Jquery, this all works. 我通过Jquery捕获外部链接,这一切都有效。

Below please find the code I am using. 请在下面找到我正在使用的代码。

// capture external link click or tap?
$(document).on('click', 'a[data-rel="external"]', function(e){
e.preventDefault();
var targetURL = $(this).attr("href");
console.log('external link: '+targetURL);
var ref = window.open(targetURL, '_system', 'location=yes');
});

I have read the phonegap documents about config.xml page link to phonegap and this is what I have added to it. 我已经阅读了关于configg 页面链接到phonegap的phonegap文档,这就是我添加到它的内容。

<preference name="phonegap-version" value="3.1.0" />
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
<plugin name="InAppBrowser" value="CDVInAppBrowser" />

I have also read about the Apple url-scheme-name and am using this in the config.xml: 我也读过Apple url-scheme-name,并在config.xml中使用它:

<gap:url-scheme name="com.canal-st.canal-st" role="None">
<scheme>mailto</scheme>
<scheme>tel</scheme>
<scheme>http</scheme>
</gap:url-scheme>

I must have missed something. 我肯定错过了什么。 Lastly I am calling mobileinit bind is being called before jquery.mobile: 最后我调用mobileinit绑定是在jquery.mobile之前调用的:

<script src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
   $.support.cors = true;
   $.mobile.allowCrossDomainPages = true;
   $.mobile.pushState = false;
   console.log('in mobileinit');
});
</script>
<script src="js/jquery.mobile-1.3.1.min.js"></script>

I know there are a lot of these types of questions on here, but none of the solutions are working, or is the new version of phonegap causing a problem? 我知道这里有很多类型的问题,但是没有一个解决方案可行,或者是新版本的phonegap导致了问题?

Your window.open should be using '_self' instead of system. 你的window.open应该使用'_self'而不是system。 Example: 例:

$(document).on('click', 'a[data-rel="external"]', function(e){
    e.preventDefault();
    ....
    var ref = window.open(targetURL, '_self', 'location=yes');
});

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

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