Jake <sp******@allte l.net> wrote in message news:88******** *************** ****@ALLTEL.NET ...
Not sure if this can be done with javascript but I would like to find a way
to detect if an image is missing and replace it with a default image instead
of the dreaded RED X showing up.
Presumably for images on a different server.
So - Is Javascript the way?
It's a trivial matter of using the onload event of each image to build
a table of references to succesfully-loaded images objects.
Then on document load, scan the document.images collection for a
match in the table. If none exists, substitute the .src propery of the
unmatched object with a specified file name.
<script type='text/javascript'>
var imageLog=[];
function replaceImage(su bstImg)
{
var iLen=document.i mages.length ,
logLen=imageLog .length ;
for(var i=0; i < iLen; i++)
{
for(var j=0; j<logLen && imageLog[j]!=document.imag es[i]; j++)
;
if(j==logLen)
document.images[i].src=substImg;
}
}
window.onload=f unction(){ replaceImage("s orry.jpg"); } // your substitute image here
</script>
In all <img> tags, add: onload='imageLo g[imageLog.length]=this'
Mozilla doesn't seem to support onerror, at least for images.
--
Stephen Chalmers
http://makeashorterlink.com/?H3E82245A