Stolen from jQuery:

jsScript.onload = jsScript.onreadystatechange = function(){
  if ( !this.loaded && (!this.readyState ||
    this.readyState == "loaded" || this.readyState == "complete") ) {

     this.loaded = true; // avoid double execution
     jQuery.isReady = true; // adviced
     doTheRest(); // execute the rest
  }
};

This you need to do before appending the script to the head.

Cheers

--
Ariel Flesler
http://flesler.blogspot.com/


On 15 mayo, 15:44, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm writing a script which is load from 3rd party sites, and my script
> depends on jQuery. In other words, I need to load jQuery from my
> script. The trick I'm using for that is to use createElement.
>
> function loadJquery() {
>   var jsScript = document.createElement("script")
>   jsScript.src = "http://mysite.com/jquery.js";;
>   jsScript.type = "text/javascript";
>   head.appendChild(jsScript);
>
> }
>
> So far so good. The problem is, in order for this to work, the
> document has to be loaded, so loadJquery is added to the onLoad event
> of "window". Of course, then I also need to run my main code, which
> depends on jQuery being loaded. Here is the problem.
>
> Apparently (at least in FF 2.0) the jQuery code is only executed
> *after* any other onLoad functions I have set before (makes sense).
> The problem is, I need to run my main code after jQuery is
> initialized. Chicken and egg problem.
>
> Any ideas? Thanks a lot!

Reply via email to