[Javascript] Detecting an image on a page

Mckinney, Lori K lkmckinn at ingr.com
Thu Jun 6 09:06:16 CDT 2002


If you want to see if the image has loaded completely, you can look at the .complete value.  If the image is there, it will be true.  Otherwise, it will be false.  

var Imgs = document.getElementsByTagName("img")
var nImgsNr = Imgs.length;

for ( var i = 0 ; i < nImgsNr ; i++ )
{
	if ( Imgs[i].complete )
		// value is 1 in your example
	else
		// value is 0
}


> you can use
> 
> var nImgsNr = document.getElementsByTagName ("img").length
>
> and nImgsNr will hold the number of img tags.
>
> Dan.


>> Hi all,
>>
>> As part of a server-uptime detection system, I want to detect with
>> javascript if an image is present on a page that has been pulled from a
>> database. Can this be done in Javascript ? Would this be the
>> document.images function ? I want to set a variable in the jscript to 1 if
>> the image is present and 0 if not - can this be don ?



More information about the Javascript mailing list