Cordova React应用-链接在iframe中不起作用

时间:2019-12-05 16:15:24

标签: reactjs cordova iframe hyperlink content-security-policy

我无法在Cordova React应用程序的iframe中打开链接。 Xcode和Safari浏览器给我这些错误:

  1. 拒绝加载https://github.com/google/roboto,因为它没有出现在内容安全策略的frame-ancestors指令中。

  2. 拒绝在帧中显示“ https://github.com/google/roboto”,因为它将“ X-Frame-Options”设置为“ SAMEORIGIN”。

  3. WF:_userSettingsForUser移动电话:{     filterBlacklist =(     );     filterWhitelist =(     );     strictWeb = 1;     useContentFilter = 0;     useContentFilterOverrides = 0;     whitelistEnabled = 0; }

  4. WF:_WebFilterIsActive返回:否

  5. 无法加载网页,并显示以下错误:操作无法完成。 (NSURLErrorDomain错误-999。)

我将链接添加到了meta标签:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data:; img-src * data: blob:; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; font-src 'self'; child-src 'self' https://github.com/google/roboto gap://ready; media-src 'none'; frame-ancestors https://github.com/google/roboto;">

,并且还在config.xml文件中使用了allow-intent和/或allow-navigation。

但是它仍然不起作用...

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

此解决方案对我有用(使用iframe中的链接):

<a href="https://github.com/google/roboto" onclick="parent.parent.cordova.InAppBrowser.open(this.href, '_system'); return false;">github.com/google/roboto</a>

使用的插件:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/