evalScripts in Prototype

I have no amazing insight to offer onthis post, but hopefully it’ll make life easier for anyone looking in to the same issues that I just had with Prototype.

We’re making a dashboard where users are dynamically adding widgets, many of which need their own javascript functions to work properly. We really don’t want to have all those functions sitting around waiting for the widgets to be loaded, but when we loaded the code in to the page after the initial page load, none of the javascript came along, it was all stripped out.

Prototype has an evalScripts option in Ajax.Updater that will allow the loaded page to contain Javascript code, but you also have to create your functions, like so:

coolFunc = function() {  // Amazing stuff! }

That’s it, nothing too fancy, and nothing amazing; but hopefully this gets the word out there a bit more and makes it easier for someone else with this problem to find the answer.