Showing posts with label Check if an image is loaded or not in javascript. Show all posts
Showing posts with label Check if an image is loaded or not in javascript. Show all posts

Tuesday, 11 December 2012

Check if an image is loaded or not in javascript

You can use javascript functions to check if an image is loaded. Here we are discussion two methods.

1) Using onload function

<script>
// Check using onload function 
 
objImg = new Image();
 
objImg.src = 'photo.gif';
 
objImg.onload = function() {   
 
// do some work   
 
}  
2) Using Complete property
<script>
// Check using complete  property 
 
objImg.src = 'photo.gif';
 
objImg = new Image();
 
 if(!objImg.complete) {  
 
// do some work   
 
} 
</script>

Hope this helps !