Why is Chrome's onerror event for the img element only fired once?

后端 未结 5 2008
时光说笑
时光说笑 2020-12-17 21:44

Why is Chrome is only calling the onerror event for the img element one time when all other browsers (IE7,8,9, FF, Opera, and Safari) all call it repeatedly?

Is ther

5条回答
  •  失恋的感觉
    2020-12-17 22:10

    I think @Mikhail is on the right track, except for a slightly different reason. In the second example, you attempt to download 2 images from the same non-existent domain www.asdfjklasdfasdf.com.

    When attempting to download bogus1.png, Chrome fails to resolve the domain to an IP address.

    When attempting to download bogus2.png (from the same non-existent domain), Chrome doesn't do anything at all... because it knows the domain lookup has failed. Whether it's correct behavior for chrome not to dispatch another onerror event might be open to debate :) I sort of expect that it should.

    To prove this, simply add 1 character to the domain name for bogus2.png and it will work as you expected.

    Edit

    One way you could force it to attempt the subsequent downloads is to change the src of the to the empty string. It's kind of hacky, but it works. You could set your rsrc attribute to something like this:

    rsrc="''|http://www.asdfjklasdfasdf.com/bogus2.png|''|http://eatfrenzy.com/images/success-tick.png"
    

    This way, when the error occurs, you set the source to ''. This seems to generate an error too, which then triggers it to try the next source...

提交回复
热议问题