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;
Maybe it's a cache problem. Try this and see whether it's working or not;
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 = null;
aimg.src = someExistedImageUrl;
In addition, check you image size.
JavaScript allocations are also limited to 10 MB. Safari raises an exception if you exceed this limit on the total memory allocation for JavaScript.
For more information, you could check This question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With