损坏图像检测_隐藏损坏的图像

损坏图像检测

损坏图像检测

I know, you don't have broken images on your site, it's unprofessional and ugly. But sometimes you may be loading images that you don't control and you never know what's going on on the other server you're expecting to serve, but it may not feel up to the task.

我知道,您的网站上没有损坏的图像,这是不专业且丑陋的。 但是有时您可能正在加载不受控制的图像,并且您永远不知道要提供服务的另一台服务器上正在发生什么,但这可能无法胜任该任务。

One nice and simple strategy to deal with this uncertainty is to hide the images that fail to load. Browsers sent an "error" event when the worst happens and an image fails for whatever reason. Subscribe to this event using your favorite event-listener-attaching approach or library and hide the image.

解决这种不确定性的一种好方法是隐藏无法加载的图像。 当最坏的情况发生且图像由于任何原因而失败时,浏览器都会发送“错误”事件。 使用您喜欢的事件侦听器附加方法或库订阅此事件,然后隐藏图像。

Or with some ugly old-school inline event handler:

或使用一些丑陋的老式内联事件处理程序:

<img 
  src="broken.png" 
  onerror="this.style.display='none'"
/>

Simple, eh?

简单吧?

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/hide-broken-images/

损坏图像检测

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值