Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
You should better use ajax for that.
There is 1 kind of request that's just perfect for this job, the HEAD request.
http://www.jibbering.com/2002/4/httprequest.html#head
read this chapter, and notice the "Does a url exist?" a bit below
Basically, it serve just to get the headers served back by the server on the ajax call end point.
Simply add a js function to be fierd upon onload, get every img tags, do check on the src, and if the return code is 40x, change the src to an generic error image.
The downside of this is that you must have your page loaded for the function to run, and that may let the user view an "red cross" in the mean time.
There is the code to get every images in the page:
Code:
var aryImg=document.getElementsByTagName('img');
for (var cptImg=0;cptImg<aryImg.length;cptImg++){
chkImg(aryImg[cptImg]);
}
Do the header code check in a function named chkImg().
Right now, this function receive a reference to the img element currently checked, so simply do the check, and update the src property if the code is 404.
For the ajax call that makes the check, I let you look for it.
It depend too much if you do everything by hand, or rely on a framework, like prototype (my favourite!)
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 09-04-2007 at 06:56 PM..
|