Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

"next gen" bookmarklet (See related posts)

With this code, create "next generation" bookmarklets.

The good points are that :
- the code is remotely loaded (so updatable and more simply testable)
- you have no length limitation
- you can dispatch the code in various libaries

To disable the browser cache, we've added a random parameter in the the last javascript url. For performance, it's better to not disable the cache but it's very useful when testing.


baseurl = 'http://example.com/bookmarklet/';

var scripts = new Array(

baseurl + 'date.js',
baseurl + 'encoding.js',
baseurl + 'http.js',
baseurl + 'bookmarklet.js?x=' + Math.floor(Math.random() * 9999)

);

for (i=0;i<scripts.length;i++) {

var x = document.getElementsByTagName('head').item(0);
var o = document.createElement('script');

if (typeof o != 'object') o = document.standardCreateElement('script');
o.setAttribute('src', scripts[i] );
o.setAttribute('type','text/javascript');
x.appendChild(o);

}


Past the code above in a bookmarklet crunchinator to generate the bookmarklet. http://ted.mielczarek.org/code/mozilla/bookmarklet.html

Not fully tested. It may have some issues.

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts