Tuesday, February 12, 2013

Bookmarklets

Regular bookmarks (aka favorites) are just locations to visit, like “http://gmail.com”. Bookmarklets are javascript code that the browser runs on the current page, and they’re marked by “javascript:” instead of “http://”.

Technically, a bookmarklet is unobtrusive script written in JavaScript and stored as the URL of a bookmark in a web browser or as a hyperlink on a web page.

Bookmarklets are saved and used as normal bookmarks. As such, they are simple "one-click" tools which add functionality to the browser.

For example, they can:

Modify the appearance of a web page within the browser (e.g., change font size, background color, etc.)

Extract data from a web page (e.g., hyperlinks, images, text, etc.)

Submit the current page to a curation service such as minus, scoop.it, link-shortening service such as bit.ly, or bookmarking service such as Delicious

Query a search engine or online encyclopedia with highlighted text or by a dialog box

Submit the current page to a link validation service or translation service

Set commonly chosen configuration options when the page itself provides no way to do this

"Installation" of a bookmarklet is performed by creating a new bookmark, and pasting the code into the URL destination field. Alternatively, if the bookmarklet is presented as a link, under some browsers it can be dragged and dropped onto the bookmark bar. The bookmarklet can then be run by loading the bookmark normally.

When clicking a bookmarklet, imagine the page author wrote <script>bookmarklet code here</script> — it can do almost anything. There are a few restrictions:

  • Restricted length: Most URLs have a limit around 2000 characters, which limits the amount of code you can run. 
  • No spaces allowed: Some browsers choke on spaces in a URL, so yourcodelookslikethis.