Reputation: 123
I'm using a function to return an image object with HTML5 canvas, but I always have an error alert (onerror event)
function GetThatImage() {
var image = new Image();
image.src = "http://localhost/assets/images/loadedsprite.png";
image.onerror = alert('Oops... Image isn\'t loaded: '+image.src);
return image;
}
Can anyone help me ?
Thanks
(sorry for my bad english)
EDIT: with this code, I have first an alert 'oops image is not loaded...' then I have 'image loaded'
function GetThatImage() {
var image = new Image();
image.src = "http://localhost/assets/images/loadedsprite.png";
image.onload = function() {
alert('image loaded');
};
image.onerror = alert('Oops... Image isn\'t loaded: '+image.src);
return image;
}
Upvotes: 2
Views: 77
Reputation: 12854
You need to set the event onerror
with an anonymous function like image.onload
.
image.onerror = function () {
alert('Oops... Image isn\'t loaded: '+image.src);
}
Upvotes: 1