homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

how to track broken image links?

5+ Year Member

Msg#: 3627438 posted 3:18 pm on Apr 15, 2008 (gmt 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+ Year Member

Msg#: 3627438 posted 5:22 pm on Apr 15, 2008 (gmt 0)

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]


WebmasterWorld Senior Member 10+ Year Member

Msg#: 3627438 posted 5:33 pm on Apr 15, 2008 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved