Page 1 of 1

[SOLVED] Is Image Loaded?

Posted: Sun Sep 11, 2005 10:23 am
by hawleyjr
Is there a way using JavaScript to telll if an image is 100% loaded?

Code: Select all

<script language="javascript">

var imgObj = new Image();
var imgObjNext = new Image();
var cssCheckCounter = 0;

function ChangeImage(){
 
   imgObj.src = img_url_from_server;//url is from an xhtml request

   updateCSS();

}

function updateCSS(){

  	if(cssCheckCounter > 5 || imgObj == 'is loaded'){ //ADD IMAGE CHECKING HERE.....
		//RUN CODE IF IMAGE IS 100% LOADED
		...
		..
		.
cssCheckCounter = 0;
	}
}else{
	cssCheckCounter++;
	setTimeout("updateCSS()",1000);
}

}

</script>

Posted: Sun Sep 11, 2005 10:26 am
by feyd
set the onload event for the image ;)