How to create Bookmarklets

This is actually a pretty neat little trick. For a while now, when I am working on simple JavaScript functions, I have been using my browsers address bar to speed things up.
For those not aware, one can actually type simple or complex JavaScript commands in the address bar of most modern browsers (It works in Mozilla and I.E at least)
for a quick simple calculator, you can try pasting this in the address bar

javascript:eval(567 * 234);

Now to create a bookmarklet, all you have to do is

  1. Create a new bookmark
  2. In the url field or the destination field, paste the javascript code you have written

You have now created a bookmarklet, that you can execute whenever you need it.

For example, to read the cookie contents of a site, you can put the following in the address bar

javascript:alert('Cookie date:\n' + document.cookie.replace(/; /g,'\n'));

or you can bookmark this link - View Cookies

Another simple bookmarklet to disable external style sheets is

Javascript:for ( ss=0; ss<document.styleSheets.length; ss++){void(document.styleSheets.item(ss).disabled=true);}

bookmarklet -> Disable Stlesheets

For those looking for more complex bookmarks, check out the following sites
Jesse’s Bookmarklet Site
Bookmarklet tool categories

Leave a Reply