Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8617 closed bug (invalid)

Error handlers only being registered on first matching element in IE

Reported by: jvz Owned by: jvz
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

To reproduce this problem, let's say we have a collection of images, some of which are hosted on a CDN, and others that might not have been synchronised with the CDN yet. To resolve this issue, we might want to set an onError event for all the img's so that they try to load a fallback URL. Example jQuery code:

$(function() {
  $("img").error(function(e) {
    this.src = this.src.replace("cdn.example.com", "example.com");
  });
});

Now the expected behaviour (as demonstrated properly by Firefox, Safari, Chrome, and Opera) is that every img element will have this error handler. However, in IE, only the first img element in the jQuery selection gets the error handler.

Commented test case

Change History (3)

comment:1 Changed 9 years ago by dmethvin

Owner: set to jvz
Status: newpending

There is a race condition in this test case. You are expecting that an error handler installed on DOM ready will catch an error event that fires when the image does not load. However, the browser may have already attempted to load the image and fired the error event before you attached the handler.

I've created a test case in jsFiddle that shows the problem can happen in other browsers, it's just a matter of timing. If you can modify this to show a problem inside jQuery we can take a look.

http://jsfiddle.net/dmethvin/cNQjY/

comment:2 Changed 9 years ago by jvz

Status: pendingnew

It's very possible that the bug I'm finding is completely due to that. Sorry, I guess I didn't fully understand how the error event is fired.

comment:3 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

Based on #8619 being opened I'm closing this one.

Note: See TracTickets for help on using tickets.