简体   繁体   English

Android上的PhoneGap不会加载外部脚本

[英]PhoneGap on Android wont load external scripts

I'm making a simple app that will load a google map. 我正在制作一个简单的应用程序,将加载谷歌地图。 but the problem is everytime I load this 但问题是每次我加载它

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

It wont run on my android emulator while on desktop it works fine. 它不会在我的Android模拟器上运行,而在桌面上它工作正常。 how can I let Phonegap or Android allow external scripts to work/load? 我怎样才能让Phonegap或Android允许外部脚本工作/加载?

UPDATE: I always get this error "Application Error: The connection to the server was unsuccessful.(file///android_asset/www/index.html). But if I removed the google map script. it works. 更新:我总是收到此错误“应用程序错误:与服务器的连接不成功。(文件/// android_asset / www / index.html)。但如果我删除了谷歌地图脚本。它的工作原理。

Actually, the whitelist is the issue like @TDeBailleul said, but he was referring to the location of the whitelist in iOS not Android. 实际上,白名单是@TDeBailleul所说的问题,但他指的是iOS中白名单的位置而不是Android。

In android, it is in /res/xml/PhoneGap.xml 在android中,它位于/res/xml/PhoneGap.xml中

There is an example of this file in this answer: https://stackoverflow.com/a/9187479/878602 此答案中有一个此文件的示例: https//stackoverflow.com/a/9187479/878602

In the lastest PhoneGap version(2.7.0). 在最新的PhoneGap版本(2.7.0)。 You should modify the file " config.xml " located in /res/ directory of your Android project. 您应该修改位于Android项目的/ res /目录中的文件“ config.xml ”。 Simply add: 只需添加:

<access origin="http://www.yourdomain.com" subdomains="true" />

Domains are assumed blocked unless set otherwise. 除非另有设置,否则假定域被阻止。

In the phonegap version 5.1 things are different than the above answers. 在phonegap版本5.1中,事情与上述答案不同。

There is a plugin installed called cordova-plugin-whitelist . 安装了一个名为cordova-plugin-whitelist Read the file at plugins/cordova-plugin-whitelist/README.md to know details. 请阅读plugins/cordova-plugin-whitelist/README.md以了解详细信息。

There are multiple kind of whitelist(navigation, intent and access-origin) and in this case you need the content-security -policy. 有多种白名单(导航,意图和访问源),在这种情况下,您需要content-security -policy。

<!-- Enable all requests, inline styles, and eval() -->
<meta http-equiv="Content-Security-Policy" content="script-src: 'self' 'unsafe-inline' 'unsafe-eval' 'https://maps.google.com'">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM