我使用简单的html标签来显示来自imgur.com的图片:
<img alt="Modern Dashboard Design" src="http://i.imgur.com/yst7lV9.png?1" style="height:550px; width:1024px" />
这是几天前的工作,但现在它没有显示。图像显示在jsfiddle上,但未在此页面上显示:
http://www.ucom.my/p/admin-page-for-website-50
当您查看页面来源时,您会找到img
标记。
可能是什么原因?
答案 0 :(得分:0)
快速查看控制台会告诉我你有很多安全错误。
拒绝加载图片“http://i.imgur.com/GAXEkpu.jpg”,因为它 违反了以下内容安全策略指令:“default-src 'self'“。注意'img-src'没有明确设置,所以'default-src' 被用作后备。
这是因为:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
这行代码存在,不允许外国来源的内容。
答案 1 :(得分:0)
打开浏览器的开发者工具。看看控制台。 阅读错误消息。
拒绝加载图片“http://i.imgur.com/GAXEkpu.jpg”,因为它违反了以下内容安全策略指令:“default-src'self'”。请注意,'img-src'未明确设置,因此'default-src'用作后备。
你已经包括:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
在您的网页中,该页面禁止在不同的域中使用<img>
元素与src
。
答案 2 :(得分:0)
查看浏览器检查员... 它说:
[Error] Refused to load http://i.imgur.com/2qEeCDA.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
[Error] Refused to apply a stylesheet because its hash, its nonce, or 'unsafe-inline' appears in neither the style-src directive nor the default-src directive of the Content Security Policy. (admin-page-for-website-50, line 87)
[Error] Refused to load http://i.imgur.com/yst7lV9.png?1 because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
[Error] Refused to apply a stylesheet because its hash, its nonce, or 'unsafe-inline' appears in neither the style-src directive nor the default-src directive of the Content Security Policy. (admin-page-for-website-50, line 89)
[Error] Refused to load http://i.imgur.com/GAXEkpu.jpg because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
答案 3 :(得分:0)
Content Security Policy: The page’s settings blocked the loading of a resource at http://i.imgur.com/2qEeCDA.png (“default-src http://www.ucom.my”).
Content Security Policy: The page’s settings blocked the loading of a resource at http://i.imgur.com/yst7lV9.png?1 (“default-src http://www.ucom.my”).
Content Security Policy: The page’s settings blocked the loading of a resource at http://i.imgur.com/GAXEkpu.jpg (“default-src http://www.ucom.my”).
Content Security Policy: The page’s settings blocked the loading of a resource at self (“default-src http://www.ucom.my”).
打开Firebug控制台时可以看到这一点。
您在head
:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
这意味着您故意阻止所有请求imgur或其他任何地方。将其更改为:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src example.com;">
或者完全删除它。