Saturday, March 10, 2007

Easier Links with Google AJAX Search API

Ever get annoyed by the complexity of adding links in blog or message board posts? Sure, it isn't rocket science, but between getting the angle brackets, quotes and start and end tags balanced correctly and getting the URL right, adding links is a pain.

This weekend I did some playing around with the Google AJAX Search API and made a nifty bookmarklet for creating links in textareas. I've only tested it with Firefox (various combinations of 1.5 and 2.0 on Linux, Windows and Mac), and it only works with plain old multi-line textareas (not 1-line text fields or rich/"wysiwyg" text controls). Aside from those caveats, it seems to work pretty well.

Installation is easy: just drag this link to your bookmark toolbar: [linkify] Note that if you're reading this in a feed reader you'll probably need to visit my site for this step, as feed readers usually strip out JavaScript. (Readlings: no smirking.)

Here's how to use it:

  1. Go to some page that has a textarea. The comments area on most blogs should work. The Blogger posting form in "Edit Html" mode also works.
  2. Type some text in the textarea.
  3. Select the part you'd like to turn into a link.
  4. Activate the bookmarklet. This will bring up a search pane on the right side of your browser window.

    screen shot

    The search query defaults to the text you'd highlighted. You can edit the query if necessary.

  5. Click on "create link" next to the search result. The popup will disappear, and the text you selected earlier (in the textarea) will be replaced with a link. The link's text will be the original selected text, and its href will be the URL of the search result you picked.

Thanks to Chris Wetherell for telling me about inter-frame communication with URL fragments, which turned out to be handy.

Update

I've been told that the bookmarklet works in Opera, but not in Safari. I'll look into the Safari issue.

posted Saturday, March 10, 2007 (25 comments)