Home

Keebler/Blog

« Flickr Bikinis getting scary
Turck MMCache for PHP »

Page Links Checker v0.1

Everyone hates landing on a 404 page when they click on a link.  On a site with many different, off-site links (like this one :) ), it’s easy for links to become inactive over time.  Here’s some Ajax (Javascript) I wrote to automatically check links on a page when a user rolls over them to make sure they’re still valid. 

When the JS file is run, it adds an onload event to the page that runs through all the links on the page, and adds an onmouseover event if one isn’t already assigned.  When a visitor moves their mouse over a link, a call is made to the server that requests the link’s URL, and a positive condition is returned if the URL is valid (http response of "200 OK").  An icon (check mark or trash can — I could use some better, small icons if anyone likes playing in Photoshop :-) ) is then displayed for the visitor in the anchor tag.

This effect would get really annoying on a site with a lot of image links since it would jam the icons into your design which could bump design elements around.  It would be easy enough to change to simply change the images if they are valid/invalid e.g. fade them, tint them, give them a border, etc.

To roll this out on a large site, you would definitely want to change it to cache the URL status.  For example, if 100 people all roll-over a link at the same time, there’s no sense checking that link over-and-over again.

Also (and this is a big one), if you have a Members-only section of your site or something, the server may not receive "200 OK"’s from the server for the password protected links.  Another thing, if a web-developer was stupid enough to pass commands in the query string without checking for session (e.g. ?deleteid=666) then the script is going to go out and hit that link and run the command. 

I’ve installed the script site-wide for now so please enjoy rolling your mouse over all my links and pinging my isp to hell :D

Cheers! 

Example (installed site-wide for now): 

  • Working site
  • Page that gives a 404 error
  • Bad URL

Download:

  • Put this JS file on your page UPDATED: July 10, 2005 @ 2pm EST Make sure you change the paths in this file to point to the PHP file below
  • Put this PHP file on your server

Related Posts

  • The MTV.ca home page is now 6.25MB in size!

This entry was posted on Sunday, July 10th, 2005 at 12:09 am and is filed under My Releases, Web Development. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

5 Responses to “Page Links Checker v0.1”

  1. Hatem says:
    July 10, 2005 at 1:51 am

    Cool script, by the way if you point to "Entries (RSS)" link in bottom page it won’t work. "feed" is not a standard protocol registered by browsers. Just and str_replace to fix it :)

  2. Jonathan says:
    July 10, 2005 at 12:54 pm

    Good point. Since that could be a problem with a lot of those special transfer protocols, I added a check that the URL begins with http:// or https://. Thanks for the suggestion :-)

    Since I am also worried about commands on the query string, I removed checking on any links with a query string.

    I also added a 500 millisecond delay to displaying the "working link" icon so it wouldn’t interfer with people clicking it.

    Another way to do this would be to check a link only when a user clicks it and display a confirmation prompt if the link is invalid e.g. "Sorry, this link no longer appears to be active.  Would you still like to go to it?  OK/Cancel".  That might be less intrusive for the user.  For the time being, I’ve added that functionality only to the active script on this site.  Try it out on this link

  3. Hatem says:
    July 12, 2005 at 12:51 am

    I’m getting a strange behaviour when I click in the “text” of your comment “https://.” is considered as URL ? (try it with firefox) I think its better to parse url in server side, easily done with preg_match, but dunno about JS…

  4. Jonathan says:
    July 12, 2005 at 6:46 pm

    Do you have a Firefox extension or Greasemonkey that automatically converts text to links? “https://” isn’t a link over here ;-)

  5. jeff salam says:
    November 28, 2008 at 4:08 pm

    hi;

    nice script ;
    I’m new to this. can you advise how I can check only the links that i can specify on the page.

    thanks
    happy thanks giving
    jeff

  • Blog Home

  • Tags

    90210 alessandra ambrosio animals asp.net audrina patridge battlestar galactica bikini bunny bush C# canada canada election ctv ctvglobemedia development Election Entertainment/Celebrity facebook Gordon Ramsay gorilla gossip girl hayden panettiere iphone last.fm liveblog liveblogging mesh08 muchmusic Music obama palin rachel bilson scribblelive shenae grimes subway telemarketers the hills the killers the office toronto ttc toronto tv us election video yeah yeah yeahs

    WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

  • Recent Posts

    • Got tickets for USA vs. Switze…
    • On my way to YYZ to fly to the…
    • RT @scribblelive: Financial Po…
    • In Olympic Skelton, Canadian M…
    • Hoping people keep putting pre…
  • Categories

    • Election
    • Entertainment/Celebrity
    • Fake News
    • Featured
    • Funny
    • Keebler/Show
    • Music
    • My Releases
    • On-the-Road
    • RedDot
    • Reviews
    • Science/Technology
    • ScribbleLive
    • Security
    • Software
    • Torrent Live Stats
    • Tweets
    • Uncategorized
    • Web Development
  • Blogroll

    • Kitten-Monkey’s Cell
    • :: kattekylling ::
    • Adam Finley
    • blog-j
    • fuzzz.gaulin.ca
    • Idiot Banter
    • mad.greyarea.com
    • ob.blog
    • PollyPrissyPants
    • RedDot CMS Users Google Group
    • ScribbleLive Official Blog
  • My Sites

    • Flickr2Facebook
    • RedDot CMS
    • ScribbleLive
    • Where are my f(acebook)ing friends?
    • WhyYouShould