gpt4 book ai didi

cordova - InAppBrowser.open 在浏览器而不是 WebView 中打开

转载 作者:行者123 更新时间:2023-12-03 22:20:20 25 4
gpt4 key购买 nike

目标是在应用程序启动时在 webview 中打开一个外部 url。

我创建了新的 Cordova 项目:

cordova create test
cd test
cordova platform add ios
cordova plugin add cordova-plugin-inappbrowser

我在 www/index.html 中内联了这个脚本:
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
cordova.InAppBrowser.open('https://google.com', '_self');
}
</script>

我用 cordova run ios 测试应用程序,应用程序启动,我得到这个:

Refused to execute a script because its hash, its nonce, or 'unsafe-inline' appears in neither the script-src directive nor the default-src directive of the Content Security Policy.



所以我添加 'unsafe-inline'到内容安全策略标签,它变成这样:
  <meta 
http-equiv="Content-Security-Policy"
content="
default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
media-src *;
img-src 'self' data: content:;">

我用 cordova run ios 测试应用程序, 应用程序启动,但打开 https://google.com在 Safari 中:

enter image description here

我到底如何在 Cordova webview 本身中打开 url?

我也试过 window.location="https://google.com" ,同样的行为。

最佳答案

我在 config.xml 中遗漏了这个:

<allow-navigation href="*" />

我不知何故错过了 the docs .

By default, navigations only to file:// URLs, are allowed. To allow others URLs, you must add tags to your config.xml:

关于cordova - InAppBrowser.open 在浏览器而不是 WebView 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47253130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com