Tony,

Let the client-side box do the work, with JavaScript. Here's a demo page
that tests for the presence of an image, and swaps the missing image with a
default image... I'm sure you can modify it to your needs:

<html>
<head>
<title>Image Not Found Test</title>
<script language="JavaScript"><!--
// make DARN sure this replacementImage file IS
// present and accounted for, or you'll get a nasty
// loop with repeated calls to this function.
// Also, enter the exact pixel dimensions of the
// replacement image. IE will respect it and resize...
// NS4 will load the replacementImage in the same
// dimensions as the missing one
var replacementImage = new Image(128,124);
replacementImage.src = '/images/notFound.gif';
function imageLoadError(myImage){
  myImage.src=replacementImage.src
return false;
}
// -->
</script>
</head>
<body>
<img src="thisfilenotavailable.jpg"
     onError="imageLoadError(this);">
</body>
</html>

Tested with IE and NS v4+ on PC; even if it doesn't work on other browsers,
it shouldn't break anything since they'll just ignore the event handler.

A big thanks to Jeff Howden at evolt.org for pointing out the onError event
handler for <img> tags to me initially.

Ron Allen Hornbaker
President/CTO
Humankind Systems, Inc.
http://humankindsystems.com
mailto:[EMAIL PROTECTED]



> -----Original Message-----
> From: Tony Schreiber [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 14, 2001 6:38 AM
> To: CF-Talk
> Subject: RE: Broken Images / Testing for file existence - JS to the
> rescue
>
>
> This sounds interesting and I seem to have missed the suggestion/code...
> What was it?
>
> > [EMAIL PROTECTED] wrote:
> >
> > > Let the client-side box do the work, with JavaScript.
> >
> > Interesting possibility.  Of course, that still clutters your
> > server log with 404 errors, which may be a consideration.  And
> > it requires additional network traffic, which may slow down the
> > page display.  But there are always tradeoffs.
> >
> > Keith C. Ivey <[EMAIL PROTECTED]>
> > Webmaster, EEI Communications
> > 66 Canal Center Plaza, Suite 200
> > Alexandria, VA  22314
> > Telephone:  703-683-0683
> > Fax:  703-683-4915
> > Web Site:  http://www.eeicommunications.com
> >
> >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to