Skip to main content
Brian Cantoni

Browser Bookmarklets

Bookmarklets (simple JavaScript snippets that perform handy actions on web pages) have been around for several years now. I’ve never written any myself, but recently found some cases that could use a little help.

My JavaScript skills are modest, but the real challenge I’ve found is making them work in both Firefox and Internet Explorer, dealing with different implementations of JavaScript and different maximum lengths of the script snippets. (Not to mention some MovableType wrangling as I write this up...).

Yahoo! Local Send

Yahoo! Local is a nice resource for finding restaurant, stores, etc., just like the old yellow pages. Unfortunately it’s hard to share the links for anything you’ve found because the URLs contain cookies and other data, making them really long.

To solve this, I wrote a simple bookmarklet that rewrites the URL, keeping only the data that is necessary. For one example, the URL length reduced from 272 to 66 characters, much easier to send via email.

This script will work from either the search results page (“Pizza near Sunnyvale, CA”) or the details page (“Giovannis Pizzeria in Sunnyvale, CA”), creating an appropriate email message that’s ready to send.

To install, drag the following link to your browsers’ toolbar: [Y!Local Send](javascript:Q%3D%5B%5D%3Bif%28location.host%3D%3D%27local.yahoo.com%27%29%20%7B%20lp%3Dlocation.pathname.replace%28/%3B.*%24/%2C%27%27%29%3Bdet%3D%28lp.search%28/details/%29%3E0%3F1%3A0%29%3Bc%3Dlocation.search.slice%281%29.split%28%27%26%27%29%3Bfor%20%28i%20in%20c%29%20%7B%20f%3Dc%5Bi%5D.split%28%27%3D%27%29%3B%20if%20%28%28f%5B0%5D%3D%3D%27csz%27%29%7C%7C%28det%26%26%28f%5B0%5D%3D%3D%27city%27%7C%7Cf%5B0%5D%3D%3D%27state%27%7C%7Cf%5B0%5D%3D%3D%27id%27%29%29%7C%7C%28%21det%26%26%28f%5B0%5D%3D%3D%27stx%27%29%29%29%20if%20%28f%5B1%5D%29%20Q.push%28c%5Bi%5D%29%7DR%3DQ.join%28%27%26%27%29%3Bu%3D%27http%3A//%27+location.host+lp+%27%3F%27+R%3Blocation%3D%27mailto%3A%3Fsubject%3D%27+encodeURIComponent%28document.title%29+%27%26body%3D%27+encodeURIComponent%28u%29%3B%7D%20void%200%3B)

So far I’ve confirmed this works on Windows XP with IE6.0 and Firefox 1.0.4. To save the bookmarklet under IE 6.0 on Windows XP SP2, you can right-click on the link, select Add to Favorites, answer Yes to the security question, and save in the Links folder.

Yahoo! Local vCard

Another missing feature from Yahoo! Local is a convenient way to save addresses you’ve found. I created a simple bookmarklet and a server CGI script that parses the detailed results page and creates a vCard. vCard files can be imported or saved in popular PIM applications like Palm Desktop, Outlook, and so on.

To install the bookmarklet, drag the following link to your browsers’ toolbar: [Y!Local vCard](javascript:if%28location.host%3D%3D%27local.yahoo.com%27%29%20%7B%20location%3D%27http%3A//cantoni.org/cgi-bin/vcard.vcf%3Furl%3D%27+encodeURIComponent%28location.href%29%3B%7D%20void%200%3B). This script only works from the “details” results page.

To save the bookmarklet under IE 6.0 on Windows XP SP2, you can right-click on the link, select Add to Favorites, answer Yes to the security question, and save in the Links folder.