Over a million developers have joined DZone.

Bookmarklet Builder

·
Write readable JavaScript code and get your bookmarklet easily.

sample.html:

alert ( "Selection: "+( // FF document.getSelection ? document.getSelection() // IE : ((document.selection && document.selection.createRange) ? document.selection.createRange().text : "unknown browser") ))
bookmarklet-builder.js: function build(js) { return "javascript:"+escape( js .replace(/\/\/.*\n/g, "") .replace(/\s+/g, " ") .replace(/\s*([=()\{\}\[\]\,]|$|^)\s*/g, "$1")) } var src = document.getElementById("src"); document.write(""+src.getAttribute("name")+""); // NOTE: in IE comments not handled 1. Put bookmarklet code into div with id=src 2. set name= text inside the link that will be displayed 3. include bookmarklet-builder.js AFTER div 4. open the html 5. test it by clicking the link 6. bookmark the link
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}