内部导航被拒绝:iOS 上的 Cordova 中的 <allow-navigation not set>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36234957/
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
Internal navigation rejected: <allow-navigation not set> in Cordova on iOS
提问by Ravi Ranjan Singh
I have built an iOS app using Cordova. The app tries to load a web page e.g. http://yourdomain.com/homein index.html. But, the page stays white blank with error in console "Internal navigation rejected - <allow-navigation> not set for url='http://yourdomain.com/home'".
我已经使用 Cordova 构建了一个 iOS 应用程序。该应用程序尝试加载一个网页,例如index.html 中的http://yourdomain.com/home。但是,页面保持白色空白,控制台中出现错误“内部导航被拒绝 - <allow-navigation> not set for url=' http://yourdomain.com/home'”。
I have already set <access origin="http://yourdomain.com/home" subdomains="true" />
and also tried by setting <allow-navigation>
tag. But the page stays blank. am I missing anything else? Please guide.
我已经设置<access origin="http://yourdomain.com/home" subdomains="true" />
并尝试通过设置<allow-navigation>
标签。但页面保持空白。我还缺什么吗?请指导。
After adding the following meta tag in index.html, the "internal navigation error" has gone, but the page is still white blank. :(
在index.html中添加如下meta标签后,“内部导航错误”消失了,但是页面还是白白的空白。:(
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script src: 'self' 'unsafe-inline' 'unsafe-eval'">
回答by Tom Kincaid
I was having this problem and it turns out there are two config.xml files. The first one is in Xcode, but you have to edit the second one from the filesystem.
我遇到了这个问题,结果发现有两个 config.xml 文件。第一个在 Xcode 中,但您必须从文件系统中编辑第二个。
AppName/config.xml
AppName/platforms/ios/AppName/config.xml
I added
我加了
<allow-navigation href="*" />
to both of them and it worked. Using 6.3.0.
对他们俩都有效。使用 6.3.0。
回答by jcesarmobile
You have to add this line to your config.xml
您必须将此行添加到您的 config.xml
<allow-navigation href="http://yourdomain.com/home" />
or this one if you want to allow the navigation to all the urls on yourdomain.com
或者这个,如果你想允许导航到 yourdomain.com 上的所有 url
<allow-navigation href="http://yourdomain.com/*" />
回答by Edmond Chui
Thanks for the pointer. The solution
谢谢指点。解决方案
<allow-navigation href="about:" />
caused a cordova prepare error for me. I need to use the following instead:
对我造成了科尔多瓦准备错误。我需要使用以下内容:
<allow-navigation href="about:*" />
回答by Yang Tsao
It's not recommend to open a url in your base web view. Use the cordova-plugin-inappbrowser and call the inappbrowser to open outer url:
不建议在您的基本 Web 视图中打开 url。使用cordova-plugin-inappbrowser并调用inappbrowser打开外部url:
function open_outer_url(url){
if(window.cordova && window.cordova.InAppBrowser){
window.cordova.InAppBrowser.open(url, "_blank", 'location=no');
}else{
window.open(url,'_blank');
}
}
回答by asgoth
It is a scheme used internally, just allow access/navigation to it:
这是一个内部使用的方案,只允许访问/导航它:
<access origin="about:*" />
<allow-navigation href="about:" />
It is not recommended to use
不建议使用
<access origin="*" />
<allow-navigation href="*" />
as described in cordova-plugin-whitelist.