Cordova - 内部超链接始终在Safari中打开 [英] Cordova - internal hyperlinks always open in Safari

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

问题描述

我对科尔多瓦很新,所以可能是我不完全明白它的目的。让我从我想要实现的总体开始。



我们有一个asp.net网站有移动支持,我基本上只是试图包装iPhone应用程式。该网站当然在IIS服务器上运行,所以我只想要一个薄的包装器启动网站,并删除地址栏,导航等。这是我的理解,你可以实现与Cordova混合方法。



我按照教程,在xCode iPhone模拟器中启动了网站,它就像我想要的一样。



我遇到的问题是网站中的超链接在Safari浏览器中启动目标页面。从我所有的谷歌,似乎这是相反的问题大多数人有。看起来大多数人都在与外部网站打开应用程序,这基本上锁定他们的应用程序。我只是试图在应用程序内从我自己的网站上从Page1到Page2。



我能用最简单的网站重现这个问题,发布相关位。在此示例中,点击第2页将在Safari中打开。



Asp.net网站: b

Page1.html

 < html> 
< a href =page2.html> Page 2< / a>
< / html>



Page2.html

 < html> 

< / html>

Cordova:



Index.html

 <!DOCTYPE html> 
< html>
< head>
< meta name =format-detectioncontent =telephone = no>
< meta name =msapplication-tap-highlightcontent =no>
< meta name =viewportcontent =user-scalable = no,initial-scale = 1,maximum-scale = 1,minimum-scale = 1,width = device-width>
< / head>
< body>
Cordova s​​ite
< / body>
< script>
window.location =http://192.168.1.157:8081/Page1.html;
< / script>
< / html>

config.xml

 <?xml version ='1.0'encoding ='utf-8'?> 
< widget id =vsisolutions.testsiteversion =0.0.1xmlns =http://www.w3.org/ns/widgetsxmlns:cdv =http://cordova.apache .org / ns / 1.0>
< name>测试网站< / name>
< description>
响应deviceready事件的示例Apache Cordova应用程序。
< / description>
< author email =dev@cordova.apache.orghref =http://cordova.io>
Apache Cordova团队
< / author>
< content src =index.html/>
< plugin name =cordova-plugin-whitelistspec =1/>
< access origin =*/>
< allow-intent href =http:// * / */>
< allow-intent href =https:// * / */>
< allow-intent href =tel:*/>
< allow-intent href =sms:*/>
< allow-intent href =mailto:*/>
< allow-intent href =geo:*/>
< allow-navigation href =http://192.168.1.157:8081/*/>
< allow-navigation href =*/>
< platform name =android>
< allow-intent href =market:*/>
< / platform>
< platform name =ios>
< allow-intent href =itms:*/>
< allow-intent href =itms-apps:*/>
< / platform>
< engine name =iosspec =〜4.1.1/>
< plugin name =com.msopentech.authdialogspec =〜0.1.6/>
< / widget>

感谢您的帮助!

解决方案

这是错误



已修复最新发布的cordova-ios 4.2.0版本



所以你不必做任何黑客来使它工作了,只需要使用 allow-navigation 标记设置您要允许在应用程序中导航的网址,其余的将在safari中打开,因为您拥有 allow-intent 为所有http和https网址设置。


I'm very new to Cordova, so it may be that I don't fully understand its purpose. Let me start with what I'm trying to achieve overall.

We have an asp.net website that has mobile support, that I'm basically just trying to wrap with an iPhone app. The site of course runs on an IIS server, so I just want a thin wrapper to launch the site, and remove the address bar, navigation, etc. It's my understanding that you can achieve that with the Cordova hybrid approach.

I followed the tutorial, and got the site to launch within an xCode iPhone Simulator, and it came up just like I wanted to.

The problem I'm having is that hyperlinks within the site launch the target page in a Safari browser. And from all of my googling, it seems like this is the opposite problem most people have. It seems like most people struggle with external sites opening within the app, which basically locks them out of their app. I'm just trying to go from Page1 to Page2 on my own site within the app.

I was able to reproduce this problem with the simplest of sites, so I'll post the relevant bits. In this example, clicking on "Page 2" will open up in Safari.

Asp.net site:

Page1.html

<html>
    <a href="page2.html">Page 2</a>
</html>

Page2.html

<html>
    Page 2
</html>

Cordova:

Index.html

<!DOCTYPE html>
<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    </head>
    <body>
        Cordova site
    </body>
    <script>
        window.location = "http://192.168.1.157:8081/Page1.html";
    </script>
</html>

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="vsisolutions.testsite" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test Site</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-navigation href="http://192.168.1.157:8081/*" />
    <allow-navigation href="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="ios" spec="~4.1.1" />
    <plugin name="com.msopentech.authdialog" spec="~0.1.6" />
</widget>

Thanks for the help!

解决方案

This was a bug

It was fixed on latest released version of cordova-ios 4.2.0

So you don't have to do any hack to make it work anymore, just have to use the allow-navigation tag to set the urls you want to allow to navigate inside the app, and the rest of them will open in safari as you have allow-intent set for all http and https urls.

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

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