Skip to content Skip to sidebar Skip to footer

Javascript Cross Domain Image Load -> Check If Loading Image Succeed Loading

I have to load image from another site (cross domain) my question is , i may can check somehow if the image has successfully loaded?

Solution 1:

Typically you would put this in a load event listener like so:

var img = newImage();
img.onload = function(){
    alert(this.src + " loaded");
}
img.src="http://example.com/images/a.png";

Solution 2:

For Javascript Check this out

http://www.sajithmr.me/javascript-check-an-image-is-loaded-or-not

I know the way aroung with jQuery.

$('#image1')
.load(function(){
    $('#result1').text('Image is loaded!'); 
})
.error(function(){
    $('#result1').text('Image is not loaded!');
});

Solution 3:

If you're loading the image in an html tag, you can use the onerror event. For example:

<img src="https://otherdomain.com/img.jpg" onerror="handleImgError();" />

If handleImgError() runs, then you know that the image didn't load properly.

Post a Comment for "Javascript Cross Domain Image Load -> Check If Loading Image Succeed Loading"