Bookmarklets

JavaScript for Bookmarklets

...the joy of oneliners!


  If you know some JavaScript, making bookmarklets is easy.

  If you don't know JavaScript, you may be able to learn it from sources on the web. Read the Netscape Javascript Guide and the Microsoft docs.

  Making bookmarklets can be a good way to learn JavaScript: there are usually only one or two ideas in each bookmarklet. I've also found them to be helpful as a sort of reference: if you can remember the effect of a bookmarklet you can usually quickly find the "cause" - the corresponding little bit of script.

  If you know JavaScript well, bookmarklets present an interesting challenge: how much functionality can you squeeze into a very tight space? There is a certain satisfaction that comes from creating an extremely elegant program.

  You can author bookmarklets in the location window of your browser and then copy and paste them into your bookmarks. You may be able to get some ideas by looking at the scripts for various bookmarklets. Note that all bookmarklets use the javascript: protocol instead of the more familiar http:// protocol used for webpage URLs.

  There are some tools in the Design section which are designed to help you study and write bookmarklets.

 
Some tips

  Keep it short! Your bookmarklet is a little program that should preferably be no more than 255 characters in length.

  Test. Test. Test. Because of subtle differences in browser implementations, you should test your bookmarklet on as many platforms as possible. Always test both Netscape and Internet Explorer on Windows and Macintosh.

  Avoid namespace collisions. Whenever possible, use long awkward variable names in order to minimize the risk of collision with other active Javascript processes. This is explained further in Ugly Variables and Encapsulation.

  Use the void. There is a void() method supported by Netscape and Explorer for use with bookmarklets. In most situations, you have to insure that returns from function calls have been voided when the bookmarklet finishes. If you don't, the last return value may get displayed in the browser window. Some things, such as alerts, don't return any value; otherwise use void().

 
For more information on making bookmarklets, read the tutorials.


Bookmarklets
Home
  See the
Bookmarklets