Add a Yahoo! Bookmark with One Click

Speed up the process of adding sites to your Yahoo! Bookmarks with a browser bookmark and a bit of JavaScript.
Yahoo! Bookmarks are an easy way to share a list of web sites across several computers. If you have a set of sites you like to visit from home, the office, a friend's house, or any other place you might find yourself in front of a computer, they'll always be just a few clicks away at your Yahoo! account, instead of trapped inside your browser at home.

Unfortunately, setting up this list of sites for the first time can be time-consuming. After logging into My Yahoo!, you must find your bookmarks (usually in the upper-right corner); click Add; copy and paste the site URL, name, and any comments into the form; and click the Save button. This might not sound too labor intensive, but it amounts to quite a few steps if you're adding more than a few sites.
If you've installed the Yahoo! Toolbar, you might have already experienced the joy of one-click Yahoo! Bookmarks. On any web page, you can click the Add Bookmark button to add a site. From then on, the site will be available at your Yahoo! Bookmarks. If you don't want to install the Yahoo! Toolbar (to save browser real estate) but still want the convenience of adding bookmarks, you can build your own JavaScript bookmarklet and add it to your browser's bookmarks toolbar to get the same one-click effect.


A bookmarklet is a bit of JavaScript code stored in a web browser bookmark. Bookmarklets give you a way to run code that can interact with the current page in the browser. For example, bookmarklets can change the size and colors of fonts on a page, open new browser windows, or extract information about the current page. With bookmarklets, you're in control of the script, because it runs when you click the bookmark.
In order to implement this hack, the only thing you'll need is a browser that has bookmarks and understands JavaScript. Don't worry, that covers just about every web browser!

the functioning bookmarklet code will be formatted without linebreaks or spaces.

// Dissected JavaScript bookmarklet for one-click Yahoo! Bookmarks
 
 // Set d to the document object as a shortcut
 var d = document;

 // Set t to the currently selected text, if available
 var t = d.selection?d.selection.createRange( ).text:d.getSelection( );

 // Build the URL that will add a bookmark to Yahoo! Bookmarks
 var url = 'http://e.my.yahoo.com/config/edit_bookmark?';
 url += '.src=bookmarks&';
 url += '.done=http%253a%2F%2Fe.my.yahoo.com/config/set_bookmark&';
 url += '.folder=1&';
 url += '.action=ab&';
 url += '.display=1&';
 url += '.protocol=http%3A%2F%2F&';

 // include the URL of the current page
 url += '.url='+escape(d.location.href)+'&';

 // include the title of the current page
 url += '.name='+escape(d.title)+'&';

 // include any selected text of the current page as a comment
 url += '.comment='+escape(t)+'&';
 url += '.save=+Save+';

 // open a new window to add the bookmark and show the results
 window.open(url,
    '_blank',
    'width=640,height=440,status=yes,resizable=yes,scrollbars=yes');

Take a look at the bold querystring variables in the code. These are the primary elements of the Yahoo! URL we're concerned with. Here's a quick look at what each variable represents:

.done
The URL to display after the action is completed.

.folder
The ID of the folder in which you'd like the bookmark to be included. If you don't have multiple folders, use 1, which is the default.

.url
The URL of the site you're adding as a bookmark.

.name
The name of the site you're adding as a bookmark.

.comment
Some arbitrary text that is associated with the bookmark.