Reputation: 1716
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.
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.
Upvotes: 1
Views: 2033
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