homepage Welcome to WebmasterWorld Guest from 54.204.127.56
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

    
how to track broken image links?
cavemanlawyer15




msg:3627440
 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--
PB

 

Achernar




msg:3627524
 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){
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]

thecoalman




msg:3627540
 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