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

« Newer Snippets
Older Snippets »
Showing 21-21 of 21 total

"next gen" bookmarklet

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.

   1  
   2  
   3  baseurl = 'http://example.com/bookmarklet/';
   4  
   5  var scripts = new Array(
   6  
   7  baseurl + 'date.js',
   8  baseurl + 'encoding.js',
   9  baseurl + 'http.js',
  10  baseurl + 'bookmarklet.js?x=' + Math.floor(Math.random() * 9999)
  11  
  12  );
  13  
  14  for (i=0;i<scripts.length;i++) {
  15  
  16  var x = document.getElementsByTagName('head').item(0);
  17  var o = document.createElement('script');
  18  
  19  if (typeof o != 'object') o = document.standardCreateElement('script');
  20  o.setAttribute('src', scripts[i] );
  21  o.setAttribute('type','text/javascript');
  22  x.appendChild(o);
  23  
  24  }


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.
« Newer Snippets
Older Snippets »
Showing 21-21 of 21 total