Using JQuery in a bookmarklet
I'm trying to create a relatively complex bookmarklet that uses jquery as well as some other large scripts. I know the trick of inserting <script> tags in order to load jquery and my own script. What I can't figure out is a reliable way to wait for jquery to be loaded so that I can continue execution of my scripts that use $. Right now I'm trying to busy-wait for $ to be defined, but sometimes that seems to totally hang my browser if there's some problem fetching jquery. I could add a timeout and fail, but this seems inelegant. If the jquery script could specify a callback argument (
http://code.jquery.com/jquery-1.4.2.min.js?callback=foo) then I could define a function foo to be invoked when jquery is loaded and that would solve my problem (that's what I'll do with my own script). But I don't think this is available. Can anyone suggest any alternative methods that will work well?