Blake Butcher

Bookmarklet template

Bookmarklets are used to trigger some JavaScript on the currently open web page. This can be useful for many situations, such as:

I use the following code to create a bookmarklet link:

<a href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://blakebutcher.com/content/example-bookmarklet.js?'+Math.floor(new%20Date().getTime()/(2*60*1000));})();">
	activate example bookmarklet
</a>

Which will render like so:

activate example bookmarklet

The users can then drags the link to their browser bookmark bar. From there they can click to activate the bookmarklet.

This bookmarklet itself just inserts a script tag that loads the specified external JavaScript file into the current page. In this case the external JavaScript just triggers a simple alert box.

It has a 2 minute cache-busting query string to ensure that the latest version of the JavaScript file is loaded.

The benefits of keeping the rest of your JavaScript outside of the bookmarklet are: