简体   繁体   中英

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.

在此处输入图片说明

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.

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM