Welcome to WebmasterWorld Guest from

Forum Moderators: phranque

Message Too Old, No Replies

how to track broken image links?

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

New User

10+ Year Member

joined:June 28, 2007
posts: 15
votes: 0

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--

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

Full Member from BE 

10+ Year Member

joined:Dec 3, 2006
votes: 1

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){

function imgOK(e){

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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 4, 2004
votes: 3

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