一致的方式来打开Phonegap应用程序在Android和iOS中的链接? [英] Consistent way to open links from Phonegap app in both Android and iOS?

查看:132
本文介绍了一致的方式来打开Phonegap应用程序在Android和iOS中的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Phonegap制作的移动应用,显示可能包含链接的新闻文章。我想让这些链接在适当的浏览器中打开,独立于应用程序。我找不到一个单一的方法,这使得在Android和iOS 相同的结果后,从Phonegap版本升级到2.0.0到2.1.0(因为你不能旋转的iOS之前的屏幕2.1)。

I have a mobile app made with Phonegap which displays news articles which may contain links. I want those links to open in a proper browser, seperate from the app. I cannot find a single way to do this which gives the same results in Android and iOS after I upgraded from Phonegap version to 2.0.0 to 2.1.0 (since you cannot rotate the screen in iOS prior to 2.1).

< a href =http:// blah> / code>

始终在应用程序中打开,没有浏览器工具栏,并且无法在不终止应用程序的情况下返回应用程序。 iOS在config.xml中遵守< access origin =http blab/> ,但Android不支持。似乎不关心 browserOnly =true属性。

<a href="http://blah">
Always opens within the app, no browser toolbars, and no way to get back to the app without terminating it. iOS obeys <access origin="http://blah" /> in config.xml but Android doesn't. Neither seem to care about the browserOnly="true" attribute.

< a href =http:// blahtarget =_ blank>

如果< access>

<a href="http://blah" target="_blank">
iPhone opens this within Safari browser if <access> allows it (or is omitted entirely), but Android opens it within the app .

< preference name =stay-c $ c>允许它(或完全省略) in-webviewvalue =false/>

将此添加到config.xml中没有什么区别。

<preference name="stay-in-webview" value="false" />
Adding this to config.xml makes no difference at all.

< a href =#onClick =navigator.app.loadUrl('http blah',{openExternal:true}); return false;>

仅在Android中支持,它会在Chrome浏览器中打开链接。 iOS中的错误。

<a href="#" onClick="navigator.app.loadUrl('http://blah',{openExternal:true});return false;">
Only supported in Android, where it opens the link in Chrome browser. Errors in iOS.

< a href =#onClick =window.open('http:// blah','_ blank ','location = yes'); return false;>

在Phonegap版本2.3.0中,这将保留在应用程序中,但显示一个便宜的浏览器工具栏顶部/底部有一个按钮,允许您返回到应用程序。这是一致的...但不是我想要的。 (在版本2.1.0中,这会导致Android在应用程序中打开,iOS会在正确的浏览器中打开。)

<a href="#" onClick="window.open('http://blah','_blank','location=yes');return false;">
In Phonegap version 2.3.0 this will stay within the app but shows a cheap-looking browser toolbar at top/bottom with a button that allows you to return to the app. This is consistent...but not what I want. (In version 2.1.0 this causes Android to open within the app and iOS to open in proper browser.)

我使用Phonegap Build ,因此此解决方案将无法正常工作。

官方文档涉及此博客文章,它是参考版本1.5.0和我的2.1.0到2.3.0发现与他们的表不匹配。

我真的不想添加一个插件的东西这个简单。

I am using Phonegap Build so this solution will not work.
The official documentation refers to this blog post which was written with reference to version 1.5.0 and my 2.1.0 to 2.3.0 findings do not match with their table.
I don't really want to add a plugin for something this simple.

有一段代码会导致设备自己的浏览器中的链接打开,在应用程序的webview之外,不管操作系统?

推荐答案

也许还不算太晚。无论如何,这是从我们的代码库,并在两个平台上工作。

Maybe it's not too late. Anyway, this is from our codebase and it works on both platforms.

openURL: function(url) {
    if(device.platform === 'Android') {
        navigator.app.loadUrl(url, {openExternal:true});
    } else {
        window.open(url, '_system');
    }
},

这篇关于一致的方式来打开Phonegap应用程序在Android和iOS中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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