Insert any Javascript bookmarklet December 10th, 2007

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.

3 Responses to “Insert any Javascript bookmarklet”

  1. David Says:

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

  2. jps Says:

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

  3. Graceful Exits » Pretending that Javascript is XSL, part 3: hCard to vCard Says:

    [...] 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. [...]