How to get HTTP status code of

前端 未结 5 1635
逝去的感伤
逝去的感伤 2020-12-07 01:44

I have a page with a lot of images that are generated server-side depending on user actions. And when image loads successfully I\'m happy, but when there is an error on the

5条回答
  •  生来不讨喜
    2020-12-07 02:13

    You cannot check HTTP status this way. However you can check if image was loaded or not using naturalWidth property.

    if (img.naturalWidth === 0) {
        // do sth
    }
    

    Hope it help.

提交回复
热议问题