Insert any Javascript bookmarklet

As the natural extension of Gareth Rushgrove’s bookmarklets for inserting the Dojo or YUI Javascript toolkits mentioned by Simon, here’s a tidying-up of a bookmarklet I’ve been using to bring in any Javascript using user input via a popup prompt:

Insert-JS bookmarklet

javascript:void(function(){
  var%20s=document.createElement("script");
  s.src=prompt("Full%20URL:");
  document.getElementsByTagName("head")[0].appendChild(s);
}())

I was originally appending it to the body as an invisible div, making use of d.innerHTML to add both src and type attributes so as to make sure the browser won’t ignore it. The above based on Gareth’s seems to work fine, though.

Comments

JP - you need to escape the "s in your bookmarklet, otherwise it gets truncated.

You're quite right, David: that's what comes of posting at 4am. Fixed now.

[...] Let’s instead assume you’re following my every word. For this next bit, you’ll need Firefox and Firebug, or to stuff all these instructions into a single file. Otherwise, you’ll have to take my word for it. Firstly, I’ve included jQuery on every page of my blog, so if you’ve got the ‘bug then you don’t have to resort to my insert-JS bookmarklet to squirt it in. [...]