I have following JavaScript code
var aimg = new Image();
aimg.crossOrigin = 'Anonymous';
aimg.onload = function () {
//execute some code when image loaded
};
aimg.onerror = function () {
//execute some code when image failed to load
};
aimg.src = someExistedImageUrl;
running on Chrome, Firefox on Linux desktop and Android devices, onload
is correctly triggered. But in iOS, onerror
is always triggered eventhough image exists and coming from same origin.
Why above code failed to load image in iOS?
Update
I add following code as suggested but does not work. The image is relatively small in size, less than 80 KB.
aimg.src = null;