Catching bad links with jquery

We’re 1 step closer to the launch of the new Poughkeepsie Farm Project website, so it’s down to some final edits before it gets flipped live.  While I was looking over the test site the other day, I realized we still had some links, and images that referred to the existing site, which would break once we did the final domain switcheroo.

I came up with the following snippet of jquery to highlight bad links and images client side so that editors would realize they needed to do something about them:

function highlight_bad() {
    $("div[id='content'] img[src^='http://farmproject.org']").css("border","9px solid red");
    $("div[id='content'] img[src^='http://www.farmproject.org']").css("border","9px solid red");
    $("div[id='content'] img[src^='http://test.farmproject.org']").css("border","9px solid red");
    $("div[id='content'] img[src^='http://pfp.dague.org']").css("border","9px solid red");
    $("div[id='content'] img[src^='http://farm.dague.org']").css("border","9px solid red");
    $("div[id='content'] a[href^='http://farmproject.org']").css("border","9px solid red");
    $("div[id='content'] a[href^='http://www.farmproject.org']").css("border","9px solid red");
    $("div[id='content'] a[href^='http://test.farmproject.org']").css("border","9px solid red");
    $("div[id='content'] a[href^='http://pfp.dague.org']").css("border","9px solid red");
    $("div[id='content'] a[href^='http://farm.dague.org']").css("border","9px solid red");
}

So every time we find a link or image that starts with an absolute url to one of the addresses the site has had inside the content block, we highlight it. This has been incredibly effective so far in catching some things I didn’t even realize was an issue.  This with the combo of drupal’s broken link detector internally is helping us ensure the content is consistent prior to launch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s