Offically, we don't support any custom javascript integration at this time. However, as you've discovered, there are a few hacks you can use that work at least some of the time.
Personally, I recommend putting the javascript you want to run inside an HTML control. I recommend this because it prevents conflicts from occuring between our code and your code. It also allows easy code reuse if you put your custom JS libraries in an HTML resource.
For your specific application, contact me directly (either through our IRC channel, or by email) and I'll see if I can help you to get your application functioning as intended.