指向外部站点的 Cordova webview 未加载图像

Posted

技术标签:

【中文标题】指向外部站点的 Cordova webview 未加载图像【英文标题】:Cordova webview which is pointing to external site is not loading images 【发布时间】:2018-09-25 19:19:11 【问题描述】:

我开发了一个托管在 Apache 中的网站(比如 xxx.com),该网站在所有桌面/移动浏览器中运行良好。它很少有图片托管在自己(xxx.com)中,很少有图片来自其他网站(yyy.com)。

我使用 Cordova 创建了一个指向 xxx.com 的 android 应用程序。删除了 Cordova_app/www 文件夹中的所有内容。它工作正常,来自self(xxx.com)的图像(html img src)加载正常,但来自其他域(yyy.com)的图像没有加载。图片不能从其他域加载的原因是什么?

任何帮助都会很棒

下面是 config.xml 的详细信息

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxx" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>xxx</name>

    <content src="https%3A%2F%2Fwww.xxx.com" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <preference name="Fullscreen" value="true" />
    <preference name="Orientation" value="portrait" />

    <allow-navigation href="https://*/*" />
    <platform name="android">a
        <allow-intent href="market:*" />
        <icon src="res/icon/android/icon.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="^5.2.2" />
</widget>

【问题讨论】:

你是如何解决这个问题的?图片正在从 https 加载,但仍然没有加载图片 【参考方案1】:

好的。我弄清楚了这个问题。来自其他域的图像是通过 http 而不是 https 调用的。由于 xxx.com 在 https 中运行,桌面和移动浏览器不会抱怨它。但是 Webview 会阻止内容。 “内容必须通过 HTTPS 提供”。

【讨论】:

以上是关于指向外部站点的 Cordova webview 未加载图像的主要内容,如果未能解决你的问题,请参考以下文章