防止图像加载错误进入javascript控制台 [英] Prevent image load errors going to the javascript console

查看:74
本文介绍了防止图像加载错误进入javascript控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如在javascript中

For example in javascript

var image = new Image();
image.onerror = function(e) {
    // handle error my way
}
image.src = "http://bad.location.com/img.jp"

我试过了

e.preventDefault()
return false

但是错误仍记录到控制台。也许这不是一件坏事,但我正在做的是将文件上传到服务器,然后处理它们并将工件加载到S3。这一切都需要很长时间。我在后台执行此操作并提前将S3 URL返回到浏览器并使用一些javascript来ping图像URL,使用image.onerror回调来检测图像是否在S3上到达。

but the error is still logged to the console. Maybe this is not such a bad thing but what I'm doing is uploading files to the server and then processing them and loading the artifacts to S3. This all takes a long time. I do this in the background and return the S3 URL's to the browser early and use some javascript to ping the image urls using the image.onerror callback to detect if the image is arrived on S3 or not.

这一切都有效但我收到了一大堆控制台错误。这有点难看。是否有任何方式
来隐藏这个。

It all works but I get a load of console errors. This is a bit ugly. Is there any way to hide this.

推荐答案

抱歉看似无法抑制这个错误,至少在谷歌浏览器中。

Sorry there is seemingly no way to suppress that error, at least in Google Chrome.

另请参阅:检查文件是否存在,但防止控制台出现404错误

这篇关于防止图像加载错误进入javascript控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆