【发布时间】:2017-06-16 21:06:33
【问题描述】:
我是 Phonegap 开发的新手,我正在尝试一些看似简单但行不通的方法。
我遵循了 Phonegap“入门”指南,并在我的 Android 手机上安装了“PhoneGap Developer”应用。我创建了一个应用程序并使用phonegap serve 为它提供服务。我删除了默认的js/index.js 并调用app.initialize() 并将以下内容添加到index.html 的位置:
<script>
function onDeviceReady() {
if (navigator.connection.type == Connection.NONE) {
navigator.notification.alert(
'An internet connection is required to continue');
} else {
navigator.notification.alert("HERE!");
window.location = "https://google.com";
}
}
document.addEventListener("deviceready", onDeviceReady, false);
</script>
如果我使用 Chrome 浏览器访问该应用程序,它会正确加载、弹出消息,然后加载 Google。如果我尝试使用 Android PhoneGap Developer 应用程序,它会弹出消息,然后什么也不做。
在 config.xml 中,我尝试将所有内容设置为尽可能宽松,以使其正常工作:
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
在服务器控制台上,我收到以下警告:
[phonegap] [console.warn] Content Security Policy has been modified to be: <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' gap: ws: https://ssl.gstatic.com;style-src 'self' 'unsafe-inline' data: blob:;media-src *;img-src * 'self' data: content:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
我对 CSP 政策不够熟悉,无法确定该政策是否真的限制加载“google.com”...
【问题讨论】:
标签: android cordova phonegap phonegap-cli