javascript - 在 Chrome 应用程序的 <img> 标签中加载外部图像

标签 javascript html google-chrome google-chrome-app content-security-policy

我想知道如何在图像标签中加载外部图像,例如:

<div id="page4">
  <img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRX1-0FwHVmDbsTFz8454Sx3fZFeQ-kO-xZ-Q6aYzMw3dCh6ybHT8TApuBPnA"/>
</div>

我必须向 manifest.json 添加什么?

出现以下错误:

Refused to load the image 'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRX1-0FwHVmDbsTFz8454Sx3fZFeQ-kO-xZ-Q6aYzMw3dCh6ybHT8TApuBPnA' because it violates the following Content Security Policy directive: "img-src 'self' data: chrome-extension-resource:".

最佳答案

应用中的内容安全政策不能放宽。

如果你想在你的应用程序中混合外部资源(在 <webview> 之外),你需要 fetch them yourself :

You can fetch remote resources via XMLHttpRequest and serve them via blob:, data:, or filesystem: URLs (see Referencing external resources).

关于javascript - 在 Chrome 应用程序的 <img> 标签中加载外部图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24199119/

相关文章:

Firefox 中的 JQUERY Galleria css 位置对齐问题。在 Chrome 中运行良好

javascript - wavesurfer.js - 让它在 Firefox 以外的浏览器中工作

javascript - Angular 2 独立组件

javascript - 未触发 Chrome 信用卡自动填充

google-chrome - 是否可以在 Firefox 或 Chrome 中查看发布请求的数据?

google-chrome - 为什么 Chrome Web Developer 工具没有列出 27.0.1453.93 版本的一些 JavaScript 文件?

javascript - 如何禁用微型滚动条 jQuery 插件?

javascript - 多个选择下拉列表的计算

javascript - 根据当前 URL 中的字符串修改源

javascript - 是否有将属性值的内容存储到 HTML 事件的最佳实践?