Bug Tracker

Modify

Ticket #8617 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by dmethvin

  • Owner set to jvz
  • Status changed from new to pending

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 2 years ago by jvz

  • Status changed from pending to new

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 2 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.