Bookmarklet


A bookmarklet is a small piece of JavaScript code that can be stored in the most popular web browsers as a URL in a bookmark or as a link on a webpage.

Because Internet Explorer uses the term favorites, instead of bookmarks or bookmarks, bookmarklets are also known under the less-used name favlets or favelets. The KDE browser Konqueror has a separate function for bookmarks, called mini-tools. This is separate from the bookmarks.

Bookmarklets can be saved as normal bookmarks. This makes it easy and fast to access tools with one click and to add useful functionalities to a web browser. For example, they can do the following: Examples

When the following lines are merged into a bookmarklet, they will search for a currently selected piece of text on Wikipedia or, if nothing is selected, the search term can be entered in a dialog: javascript:(function(){q=document.getSelection(); if(!q){void(q=prompt('Wikipedia zoekterm:',''))}; if(q)location.href='http://nl.wikipedia.org/w/wiki.phtml?search='+escape(q)})()

The following example sets the right margin to 45% to make Wikipedia more readable: javascript:(function(){var newSS, styles='body { margin-left:0%; margin-right:45%;}';if(document.createStyleSheet) {document.createStyleSheet(%22javascript:'%22+styles+%22'%22); } else { newSS=document.createElement('link'); newSS.rel='stylesheet'; newSS.href='data:text/css,'+escape(styles); document.getElementsByTagName(%22head%22)[0].appendChild(newSS); } })(); History

Steve Kangas of | bookmarklets.com invented the term bookmarklet, which he began to develop following an idea in the Netscape JavaScript Guide. The term favlet was invented by Tantek Çelik.

Brendan Eich, who developed JavaScript with Netscape, gave this reason for his invention of the javascript: -URL (which makes bookmarklets possible):

They were a deliberate feature in this sense: I invented the javascript: URL along with JavaScript in 1995, and intended that javascript: URLs could be used as any other kind of URL, including being bookmark-able.

In particular, I made it possible to generate a new document by loading, e.g. javascript:'hello, world', but also (key for bookmarklets) to run arbitrary script against the DOM of the current document, e.g. javascript:alert(document.links[0].href). The difference is that the latter kind of URL use an expression that evaluates to the undefined type in JS. I added the void operator to JS before Netscape 2 shipped to make it easy to discard any non-undefined value in a javascript: URL.

wiki