【发布时间】:2016-03-16 13:01:34
【问题描述】:
我是 Cordova 的新手,需要一些帮助来完成一项简单的任务。
我有这个 hello world 应用程序,我试图在应用程序 WebView 上加载一个外部 url,我使用的代码是由 cordova 生成的,我对其所做的唯一更改是:
- 在 index.html 文件中添加了指向
http://www.google.pt的链接。 - 在 config.xml 文件中添加了
<allow-navigation href="*" />。
我已仔细阅读文档,据我所知,这个非常简单的更改应该允许我在应用程序中加载 url,但是它没有。单击链接后,Safari 将打开并加载谷歌。我需要它在应用程序中加载,而不是在 safari 中。
我已经在 android 上测试了完全相同的东西,它运行良好。
这是我的 config.xml 文件:
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</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:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<allow-navigation href="*" />
</widget>
这是我的 index.html 文件:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<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">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<div style="margin-top: 20px; border: 1px solid grey;">
<a href="http://www.google.pt/">Google!</a>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
我正在使用 cordova 6 并在 ios 模拟器上使用 ios 9.2 进行测试,也使用 8.1 进行了测试,但也无法正常工作。
知道有什么问题吗?
谢谢, 西普里
【问题讨论】:
-
我也遇到了这个问题。以下解决方案无效。