A handy way to work around the 508-character limit on bookmarklets in IE. Apparently there are no limits in Netscape/Mozilla. original ref.

javascript:void((function() {var element=document.createElement('script');
element.setAttribute('src','http://www.here.there/myscript.js');
document.body.appendChild(element)})())

Basically just adds a script element to the current document. This will be loaded by the browser and any Javascript processed automatically. Obviously the loaded script can't all be functions, there must be at least a line or two of code to trigger some processing.

I've checked and this technique works in Mozilla 1.2 as well as IE, so its probably a good idea to always write bookmarklets in this way.

Advantages: you can change/update the code without existing users having to upgrade. Disadvantages: requires that extra network hit, so is probably only useful for more complex bookmarklets.

However because there is a network round-trip, you could do some funky things with cookies. E.g. allow the script to store data on the remote server (assuming the user wants to, and its not sensitive). This data could be used to affect the client-side processing.

Might be an interesting way to allow a bookmarklet to be customised by the user (download the custom parameters, etc in a cookie) or allow multiple users to interact: server can collect data from all users, and then 'broadcast' it back when the script/cookie is pulled again. Might be possible to build collaborative click-streams this way. Using it as an annotation mechanism is another obvious idea.

Here's another interesting possibility: The bootloader can actually reference a javascript file that is actually created dynamically, e.g. using a JSP page. Parameters can also be passed to the JSP page, if the bootloader is extended slightly to extract some useful context from the page (obviously keeping to the character limit). This would give quite a bit of flexibility, especially if the bootloader bookmarklet was also dynamically generated so that it contains a login (e.g. a hashed key value) which could be used to retrieve configuration data stored for that user.

You can then customise the javascript code dropped into the page according to the users preferences. Seems there's a lot of mileage in this technique. Including implementing User Centred Linking. Here's the use case:

  • Bob Jones registered at MyBookPreferences.com, and stores along with his profile, his preferred online bookstore (which may include his library)
  • Bob then drags the "BookRedirect" bookmarklet to his browser toolbar
  • Bob then browses the web, reading his favourite blogs. On one blog he finds a number of links to books that he's interested in, and may like to buy.
  • Bob clicks his BookRedirect bookmarklet.
  • The bookmarklet (actually a bootloader) downloads a javascript file from MyBookPreferences.com. This javascript file is automaticaly generated from Bobs profile. Bob's profile is identified using a hashed "magic key" in the javascript URL.
  • The javascript file is inserted into the page and executes. It trawls through the page and spots all Amazon links and rewrites those anchor elements so they actually point to Bobs preferred supplier.
  • Bob then clicks the inline links to purchase the book.

This seems pretty straight-forward to me and is a taster of the power of this technique.

A slightly more esoteric (and frankly bizarre) version of this would be to include URNs not URLs in the original page. Someone could then use a bookmarklet as their URN resolver. The bootloader bookmarklet could make a first pass over the current document to spot the URN schemes used, and pass them as parameters to the remotely generated Javascript file.

Add new attachment

In order to upload a new attachment to this page, please use the following box to find the file, then click on “Upload”.
« This page (revision-1) was last changed on 18-Mar-2003 08:47 by unknown [RSS]