> > I'm afraid that I simply don't take Safari users into > > account. Hardly a great thing, but I focus on three > > browsers: Firefox and IE7, and then IE6. > > In that order. The work I do is targetted at corporate > > users who run Windows 2000 and Firefox, and all the > > JS work I do is for those users.
> Then your solution is almost OK for you. Here is a usable > version ;-) > > (function() { > var addScriptCounter = 0; > > function addScript( url, callback ) { > var script = document.createElement( 'script' ); > script.myLoadHandler = callback; > script.id = 'dynamicallyLoadedScript_'+addScriptCounter; > script.type = 'text/javascript'; > script.charset = 'utf-8'; > script.src = url; > > var script2 = document.createElement( 'script' ); > script2.type = 'text/javascript'; > script2.charset = 'utf-8'; > script2.appendChild( > document.createTextNode( > '(function(){'+ > 'document.getElementById(\'dynamicallyLoadedScript_'+ > addScriptCounter+'\').myLoadHandler();})()'; > )); > > var head = document.getElementsByTagName('head')[0]; > head.appendChild( script ); > head.appendChild( script2 ); > > addScriptCounter++; > } > })() > > Usage: > > addScript('jquery.js', function() { > alert('horay, jQuery is available'); > }); > alert('jQuery is not necessarily available here'); > > The second script tag will be evaluated after the first one > has been loaded and evaluated. At least that works for all > browsers I have tested with, except those Safari versions > and very old browsers without a usable DOM implementation. That looks really dodgy, sorry. What if the browser downloads script and script2 at the same time, and script2 finishes first? Instead, simply edit your copy of jquery.js and add one like of code at the end of the file, to call a "ready" function that you've defined in your already-running code. If you have jQuery plugins that your code depends on, merge them all into jquery.js and add that function call at the very end. Hmm... This would make a nice patch for jQuery itself - when it concatenates all the files to make the various "dist" versions, add this line to the end of the merged code: window.jQuery_onload && jQuery_onload(); John et al, what do you think? -Mike -Mike _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/