Jaydeep
Jaydeep

Reputation: 1716

Images not loading in IE11

I have a remote url for an image which I have to display. Below is the snippet of code.

var tempImage = new Image();
tempImage.onload = function() {
  console.log('image loaded');
};
tempImage.src = url;

This is working fine in Chrome, Firefox and Edge. But in IE11, onload event is not getting triggered.

In chrome's network tab I have seen image starts downloading once finished it triggers the onload event. But for IE11, In network tab, I found the image is not getting downloaded completely, which seems to be the reason because of which neither image is getting displayed nor onload is getting triggered.

enter image description here

Is there any way to handle this situation. Any hints will be really appreciated.

EDIT 1 Post adding new keyword before function, onload is getting triggered but image is getting displayed as cross.

enter image description here

Upvotes: 1

Views: 2033

Answers (1)

P_Andre
P_Andre

Reputation: 791

This is a known problem in IE11.

var tempImage = new Image();
tempImage.onload = new function() {
  console.log('image loaded');
};
tempImage.src = url;

The above code should solve your problem. Note that the only difference is addition of the key word "new" before "function" on line 2.

Upvotes: 1

Related Questions