最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PhoneGap on Android wont load external scripts - Stack Overflow

programmeradmin0浏览0评论

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=""></script>

It wont run on my android emulator while on desktop it works fine. how can I let Phonegap or Android allow external scripts to work/load?

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.

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./maps/api/js?sensor=false"></script>

It wont run on my android emulator while on desktop it works fine. how can I let Phonegap or Android allow external scripts to work/load?

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.

Share Improve this question edited Feb 21, 2012 at 3:39 psycrow117 asked Feb 21, 2012 at 3:14 psycrow117psycrow117 631 silver badge6 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Actually, the whitelist is the issue like @TDeBailleul said, but he was referring to the location of the whitelist in iOS not Android.

In android, it is in /res/xml/PhoneGap.xml

There is an example of this file in this answer: https://stackoverflow./a/9187479/878602

In the lastest PhoneGap version(2.7.0). You should modify the file "config.xml" located in /res/ directory of your Android project. Simply add:

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

Domains are assumed blocked unless set otherwise.

In the phonegap version 5.1 things are different than the above answers.

There is a plugin installed called cordova-plugin-whitelist. Read the file at plugins/cordova-plugin-whitelist/README.md to know details.

There are multiple kind of whitelist(navigation, intent and access-origin) and in this case you need the 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.'">
发布评论

评论列表(0)

  1. 暂无评论