Detect “image corrupt or truncated” in Firefox

前端 未结 2 1624
清酒与你
清酒与你 2020-12-31 05:31

(Pre-emptive strike: If you\'re tempted to mark this as a duplicate, note that other questions seem to ask \"why am I getting this error?\" I know why I\'m getting this erro

2条回答
  •  無奈伤痛
    2020-12-31 06:10

    I was dumbfounded by this issue today myself. Everything was working fine (the images loaded visually as expected) except that the error kept showing up in Firefox error console - no such errors in IE or Chrome though.

    In my case I was plugging an image into a div with innerHtml in an on complete jquery handler. The errors stopped when I preempted the jquery call with:

    var image_holder = new Image();
    image_holder.src = img_path;//path of image that's going to be plugged in  
    

    It worked for me, but it still makes no sense. I assume it's something to do with timing as this code initiates the image to load before it gets to the code that actually plugs it into the page.

提交回复
热议问题