Tuesday, January 25, 2011

Adding favicon to Firefox bookmarklets on the bookmarks bar

This bookmarklet loads a PubMed search into UCT's e-journal search engine. It also has a favicon using the technique from Restafarian.org » Adding an Icon to Your Bookmarklet. To create the bookmarklet, first create a bookmark on the Firefox bookmark toolbar. Right click the bookmark, select Properties, and change URL to:
javascript:if(window.location.href.indexOf('file:///C:/')==0){'%3Chtml%3E%3Clink%20rel="icon"%20href="http://www.ncbi.nlm.nih.gov/favicon.ico"%3E';}else{metaTags=document.getElementsByName('ncbi_uidlist');i=metaTags.length;if(i>0){location='http://uctsfx.hosted.exlibrisgroup.com.ezproxy.uct.ac.za/uct?rft_id=info:pmid/'+metaTags[0].content}else{location.href='http://www.ncbi.nlm.nih.gov/pubmed'}}

Afterwards go to C drive and click on bookmarklet to load the icon. Thereafter you can go to any site (other than C drive) and the bookmarklet will execute the javascript. You can change the icon location to e.g. file:///C:/pub/firefox/favicons/pubmed.ico. The javascript for the actual bookmarklet function can also be changed and is located inside the else {} statement.