如何在一个地方检测图像上的403错误? [英] How to detect 403 Errors on images in one place?
本文介绍了如何在一个地方检测图像上的403错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我的网站在阻止某些域的组织内使用时会引发此错误 - 即社交网站等。它们只是使用< img src =>链接到这些域上的图像。
This error is thrown when my site is used inside an organization that blocks certain domains - i.e. social sites etc. They are just links to images on these domains using <img src = "">
来自Chrome控制台
无法加载资源:服务器响应状态为403
(禁止:拒绝类别)
跟随URL
Failed to load resource: the server responded with a status of 403 (Forbidden: category denied) "Followed by URL"
如何以实用方式检测此错误并改为显示默认图像?
How can I detect this error pragmatically and have a default image display instead?
推荐答案
I发现这个:
function imgError(image){
image.onerror = "";
image.src = "/images/noimage.gif";
return true;
}
<img src="someimage.png" onerror="imgError(this);"/>
这篇关于如何在一个地方检测图像上的403错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文