Html 错误:Phonegap 中的白名单拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10795628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Whitelist rejection in Phonegap
提问by Neji
I'm new to mobile development. I'm using Phonegap/Cordova to create a cross-platform app. My code works well on Android but when I'm porting it to iPhone it's showing an error:
我是移动开发的新手。我正在使用 Phonegap/Cordova 创建一个跨平台的应用程序。我的代码在 Android 上运行良好,但是当我将它移植到 iPhone 时,它显示了一个错误:
[143:2003] ERROR whitelist rejection: url="abc"
Now can I overcome this problem?
现在我能克服这个问题吗?
回答by nhahtdh
Notice: This answer only applies for PhoneGap version 1.x and below. From version 2.x onwards, whitelist configuration is done via
cordova.xml
.
注意:此答案仅适用于 PhoneGap 1.x 及以下版本。从 2.x 版本开始,白名单配置通过
cordova.xml
.
You have to add allowed URLs into PhoneGap.plist's (or Cordova.plist) ExternalHosts array.
您必须将允许的 URL 添加到 PhoneGap.plist(或 Cordova.plist)的 ExternalHosts 数组中。
For example, if you want to allow access to this URL http://www.myhost.com/path/file
, then add www.myhost.com
as a new entry to ExternalHosts
array.
例如,如果您想允许访问此 URL http://www.myhost.com/path/file
,则将其www.myhost.com
作为新条目添加到ExternalHosts
数组中。
If you want to allow access to content on all the subdomain of Google (e.g. maps.google.com
, mails.google.com
), you can add *.google.com
as a new entry to ExternalHosts
array.
如果您想允许访问 Google 的所有子域(例如maps.google.com
, mails.google.com
)上的内容,您可以将其*.google.com
作为新条目添加到ExternalHosts
数组中。
I am not sure why you get "abc" in the link, though. Do you have "abc" as a link to anything? Is it URI fragment?
不过,我不确定你为什么在链接中得到“abc”。你有“abc”作为任何东西的链接吗?是URI片段吗?
回答by Ivan
In PhoneGap 3.0, you need to edit config.xml in Project folder (note: not the www/config.xml)
在 PhoneGap 3.0 中,您需要编辑 Project 文件夹中的 config.xml(注意:不是 www/config.xml)
<access origin="*" />
回答by shawkinaw
In PhoneGap 3.0, you need to edit www/config.xml
, and add/edit <access>
tags. For example, if you want to allow everything, change the tag to:
在 PhoneGap 3.0 中,您需要编辑www/config.xml
、添加/编辑<access>
标签。例如,如果您想允许所有内容,请将标签更改为:
<access origin="*" />
回答by Manish Agrawal
You can add this following code in Cordova.plist file:
您可以在 Cordova.plist 文件中添加以下代码:
<key>ExternalHosts</key>
<array>
<string>*.facebook.com</string>
</array>
With *.facebook.com
as the domain name, you can use two different sub-domains.
随着*.facebook.com
作为域名,可以使用两种不同的子域。
回答by wael
You will have to Domain Whitelist so you can access outside domains such as http://google.com.
您必须加入域白名单,以便您可以访问外部域,例如http://google.com。
In iOS (Cordova > 3.0.0), the whitelisting rules are found in AppName/config.xml
and declared with the element <access origin="..." />
在 iOS (Cordova > 3.0.0) 中,AppName/config.xml
可以在元素中找到并声明白名单规则<access origin="..." />
You can also use wildcards to declare domains. For example, to allow access to all subdomains and TLDs (.com, .net, etc) of Google, use *.google.*
您还可以使用通配符来声明域。例如,要允许访问 Google 的所有子域和 TLD(.com、.net 等),请使用*.google.*
Reference: Domain Whitelist Guide
参考:域白名单指南
回答by bharath gangupalli
Even I got the same issue... I fixed it in the below way..In cordova.plist--> under ExternalHosts array menu, add an item as * or .. So it allows all the external links... if u have to mention one by one mention it as .facebook.,*.google.* etc.
即使我遇到了同样的问题......我用下面的方式修复了它......在cordova.plist-->在ExternalHosts数组菜单下,添加一个项目为*或。. 所以它允许所有的外部链接......如果你不得不一一提及它作为.facebook。,*.google.* 等
回答by DC9999
This is because phonegap won't take external urls .For phonegap older versions below 2.x
we need to set url in cordova.plist
like this.
这是因为 phonegap 不会接受外部 url。对于下面的 phonegap 旧版本,2.x
我们需要cordova.plist
像这样设置 url 。
ex:*.google.co.in
(u can put your url after *. this) and OpenAllWhitelistURLsInWebView
---to ---YES
.
例如:(*.google.co.in
你可以把你的网址放在 *.this 之后)和OpenAllWhitelistURLsInWebView
---to --- YES
。