jQuery: The Write Less, Do More JavaScript Library

Loading jQuery dynamically

View: New views
2 Messages — Rating Filter:   Alert me  

Loading jQuery dynamically

by Christophe-18 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

I need to load jQuery in a dynamic an synchronous way. How can I do
that?

It seems that the usual ways to dynamically load scripts (like DOM
insert) are all asynchronous. Basically, I am looking for a function
like getScript, outside jQuery.

Thanks!

Re: Loading jQuery dynamically

by unwired brain :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 22, 2009 at 04:19, Christophe <christophe.humbert@...> wrote:
> It seems that the usual ways to dynamically load scripts (like DOM
> insert) are all asynchronous. Basically, I am looking for a function
> like getScript, outside jQuery.

var scriptLoader = document.createElement("script");
scriptLoader.src = "http://bit.ly/jq132m";
scriptLoader.onload = scriptLoader.onreadystatechange = function () {
    if (!this.readyState || "loaded" === this.readyState || "complete"
=== this.readyState) {
        // replace the following line with something that properly
suits your needs
        alert("jQuery " + jQuery.fn.jquery + " has loaded successfully
and is up and running!");
    }
};
document.documentElement.appendChild(scriptLoader);

Hope it's what you're looking for.
--
Massimo Lombardo
Linux user #437712