我在Phonegap开发方面是全新的,我正在尝试一些看起来很简单但不工作的东西。phonegap window.location = url不工作
我遵循了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浏览器访问的应用程序,使弹出消息,然后加载了谷歌。如果我尝试使用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”或不...
任何想法为什么开发工具不允许所有的导航,以促进发展?对我来说这似乎很奇怪。 –
我不知道,但在我看来,创建Cordova/Phonegap应用程序导航到Cordova webview中的外部网站是一种不好的做法。要导航到外部网站,您可以使用inAppBrowser插件。 – jcesarmobile
我一般同意你的看法,但这是一个仅限于开发者的工具。 –