a weblog by Ed Eliot

Full of lovely web standards information and a large helping of PHP

This weblog is the online home of , a Senior Technical Manager at GCap Media living and working in London, United Kingdom.

Entries for May 2007

You are currently viewing posts from the archive. Click here to return to the latest posts.

  • Do links on your site make sense out of context?

    11 months, 26 days ago

    If they don't, then they should. It's far to easy to create links labeled "click here" or "read more" but these are next to useless when not supported by the context of their surrounding text. Imagine how you'd decide which of these links to visit if they were displayed listed as a simple list of links. An unrealistic situation you might say, but you'd be wrong - this is exactly the situation faced by blind and partially sighted users every day. Popular screen reader software like JAWS and Window Eyes provide mechanisms for browsing through all links found in a page, the aim being to allow users to more quickly find the information they're after. Similar mechanisms exist for headings and other page elements but these are next to useless if you haven't labeled things correctly. Some argue that one can expand the meaning of a link through it's title attribute but this unfortunately proves to be a bit hit and miss - many screen readers don't read text in title attributes by default.

    To add more salt to the wound let's turn to search engine crawlers. These place high importance on the text you assign to links so you're missing a trick if you continue to mislabel links in this way. Ever wanted to know the biggest culprits of the "click here" link? Simply search for this text in Google.

    A Script To Highlight The Problem

    In my own posts I try reasonably hard to ensure links make sense out of context but sometimes I slip up. I can think of several instances of really poorly labelled links in previous posts and I really need to go back and correct them. In an attempt to highlight these failings going forward and because it seems like a useful additional navigation aid I've developed a simple script which extracts all links from a post and adds them to a new section in the side bar on the fly.

    Note: It's not on my site yet as I need to do a little CSS restructuring to accomodate it first.

    1. var oExtractedLinks = {
    2. iHeadingLevel : 3,
    3. sHeadingText : 'Links in Post',
    4. sParentId : 'post',
    5. Init : function() {
    6. // check for DOM support and valid parent id
    7. if (!document.getElementById || !document.getElementById(this.sParentId)) {
    8. return false;
    9. }
    10. this.Process();
    11. },
    12. Process : function() {
    13. // get links contained in parent
    14. aLinks = document.getElementById( this.sParentId ).getElementsByTagName('a');
    15. // get number of links
    16. iNumLinks = aLinks.length;
    17. // does the parent actually contain any links
    18. if (iNumLinks) {
    19. // get script node, we'll insert everything relative of this to remove need for extra markup
    20. var oParent = document.getElementById('extracted-links');
    21. // create heading and list
    22. var oHeading = document.createElement('h' + this.iHeadingLevel);
    23. var oList = document.createElement('ul');
    24. // add specified text to heading
    25. oHeading.appendChild( document.createTextNode(this.sHeadingText) );
    26. // insert into document
    27. oParent.parentNode.insertBefore(oHeading, oParent);
    28. for (var i = 0; i < iNumLinks; i++) {
    29. // add link to list
    30. this.AddLink(oList, aLinks[i]);
    31. }
    32. // insert list into document
    33. oParent.parentNode.insertBefore(oList, oParent);
    34. }
    35. },
    36. AddLink : function(oList, oLink) {
    37. // make sure the first node of the link isn't an image
    38. if (oLink.firstChild.nodeName.toLowerCase() != 'img') {
    39. // create list item and anchor
    40. var oListItem = document.createElement('li');
    41. var oItemLink = document.createElement('a');
    42. // get attributes from source link
    43. oItemLink.setAttribute('href', oLink.getAttribute('href'));
    44. oItemLink.setAttribute('title', oLink.getAttribute('title'));
    45. oItemLink.appendChild( document.createTextNode(oLink.firstChild.nodeValue) );
    46. // append anchor to list item
    47. oListItem.appendChild(oItemLink);
    48. // append list item to list
    49. oList.appendChild(oListItem);
    50. }
    51. }
    52. }
    53. // run the script, we're not using onload or DOM ready so the script won't pick up links appearing after the script reference
    54. oExtractedLinks.Init();

    View a live demo of the script

    Having downloaded the script, to use in your own site simply add the following line into your page at the point at which you'd like the links to appear. Also make sure you update sParentId with the ID of the element containing the links you'd like to extract.

    Screen Readers

    If you're new to the way screen readers work I'd highly recommend heading over to the YUI Blog and watching Yahoo!'s Accesibility Project Manager demonstrate how they're used.

    A demo version of JAWS is available which can be used for up to 1/2 hour at a time. After this you'll have to reboot your computer before continuing to use it.

    Further Reading

  • Public Bazaar Repository

    1 year, 12 days ago

    I've just finished setting up a public Bazaar repository for the various libraries and snippets of code I distribute on this site.

    What's Bazaar?

    It's a distributed version control system written in Python which is really simple to use. Stuart, who introduced me to it wrote a detailed post explaining how it works. I'd definitely recommend checking that out as well as Bazaar's own online documentation which is very thorough.

    My Repository

    My repository is located at http://bazaar.ejeliot.com/. Browsing to it in a web browser will show you a listing of what's available.

    Checking out a copy of one of my libraries is simple. With Bazaar installed you can grab a copy of my PhpDelicious library, for example, by running:

    1. bzr branch http://bazaar.ejeliot.com/php-delicious

    In due course I'll be going back through my blog archive and linking to this repository from the relevant posts as well as trying to automate generation of the corresponding zip file downloads from it.