Welcome to WebmasterWorld Guest from 54.198.87.238

Forum Moderators: phranque

Message Too Old, No Replies

how to track broken image links?

     
3:18 pm on Apr 15, 2008 (gmt 0)

5+ Year Member



Let's say you have a Press page where you link to news articles, and borrow the source's logo directly from their site (instead of copying the image file and hosting on your server). If they one day delete it, or change the file name, the only way to know would be to look at the broken link on your site.

But is there a better way? How can one be notified of broken IMG SRC links?

Thank you wise ones--
PB

5:22 pm on Apr 15, 2008 (gmt 0)

5+ Year Member



On one of my sites I've set up a javascript system that notifies the site when images have failed to load.

Basically, you end each page with:

<script type="text/javascript">chkI()</script>

and define chkI()
function chkI(){
function imgE(e){
e=e¦¦event;
e=e.target¦¦e.srcElement;
if(e.Cap)return;
e.OK=0;e.Cap=1
}

function imgOK(e){
e=e¦¦event;
e=e.target¦¦e.srcElement;
e.OK=1;e.Cap=1
}

for (var i=0,e;e=document.images[ i ];i++) {addEvent(e,'error',imgE);addEvent(e,'load',imgOK)}
}

addEvent() is a standardized method for addEventListener() (Mozilla) and attachEvent() (IE)

You add a body.onload event that loops through the images and detects which have failed. Once done, you can report failed urls to your server by requesting a dummy image with urls as parameters (after '?').

When you parse you server logs you'll notice all image errors (temporary and permanent).

[edited by: Achernar at 5:23 pm (utc) on April 15, 2008]

5:33 pm on Apr 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use a server side scripting language like php to see if the file exists before generating the html code.

Having said that make sure you have permission of the website to hot link to their images. You may just end up serving a not so nice image to whoever is viewing your pages. ;P

 

Featured Threads

Hot Threads This Week

Hot Threads This Month