It works fine for me in the current nightly. Here are a couple of test
cases:

http://mg.to/test/jquery/dynamic-nightly/jquery-dynamic.html

http://mg.to/test/jquery/dynamic-nightly/jquery-dynamic-onload.html

The first one loads jQuery when you click a button; the second does it from
an onload attribute.

I'm not using any of the onreadystatechange stuff. Instead, I appended a
function call to the end of the jquery.js file that I'm using.

-Mike

On Fri, Oct 9, 2009 at 10:30 AM, Sasha Sklar <sashask...@gmail.com> wrote:

>
> I came across this issue while looking at LAB.js. Is this known to be
> fixed in latest nightly? From what I can tell document.ready still
> won't fire if jQuery is loaded after DOM Ready has occurred. Here's my
> test code:
>
> // make sure dom ready has already happened by attaching an event to
> old school window.onload
> window.onload = function() {
>        console.log('window onload fires');
>        var url = "http://code.jquery.com/jquery-nightly.js";;
>         var head = document.getElementsByTagName("head")[0], done = false;
>        var script = document.createElement("script");
>        script.src = url;
>
>        script.onload = script.onreadystatechange = function() {
>         if (!done && (!this.readyState || this.readyState == "loaded" ||
> this.readyState == "complete")) {
>                         console.log('jquery nightly is done loading');
>                done = true;
>                        $(document).ready(function() {
>                                console.log('dom ready functions should fire
> now');
>                        });
>
>                }
>        };
>
>        head.appendChild(script);
> };
>
> - Sasha
>
> On Oct 8, 5:18 pm, Michael Geary <m...@mg.to> wrote:
> > Failing to run the document ready functions is a bug in jQuery 1.3.2 that
> is
> > fixed in the current svn. It now calls document.ready listeners even if
> you
> > load jQuery and subsequent document ready functions dynamically.
> >
> > At least I *assume* that it's a bug that was fixed, and not just an
> > accidental improvement! :-)
> >
> > Try your code with the nightly you can get here:
> >
> > http://docs.jquery.com/Downloading_jQuery#Nightly_Builds
> >
> > Regarding the onload for the script, the best way to handle this is to
> make
> > a custom copy of jquery.js or jquery.min.js and add a line to the end:
> >
> > window.jQueryLoaded && jQueryLoaded();
> >
> > Then you provide a global jQueryLoaded() function before loading jQuery,
> and
> > that has your other initialization code (using document ready if you want
> > with the new jQuery code).
> >
> > Or you can add whatever initialization code you want at the end of your
> > jquery.js file.
> >
> > -Mike
> >
> > p.s. Speaking of jQuery svn, are there nightly builds or the like
> >
> > On Thu, Oct 8, 2009 at 6:11 AM, Ryan Crumley <crum...@gmail.com> wrote:
> >
> > > Rob,
> >
> > > Point taken about using onLoad for a script tag possibly not being
> > > supported. In this case however that part of the code is working fine.
> > > The issue I am having is related to jQuery being added to a page after
> > > the page has completed loading. When this happens ready listeners are
> > > never executed. If jQuery is present when the page loads then ready
> > > listeners are executed as expected.
> >
> > > Ryan
> >
> > > On Oct 8, 12:45 am, RobG <robg...@gmail.com> wrote:
> > > > On Oct 8, 10:04 am, Ryan Crumley <crum...@gmail.com> wrote:
> >
> > > > > I am experiencing unexpected behavior using $(document).ready() on
> a
> > > > > page where I inject jQuery after the page has loaded and then
> attach
> > > > > listeners to the ready event. The ready() event is never called
> using
> > > > > Firefox and Safari however it is called using IE.
> > > > [...]
> > > > >                 function loadjquery() {
> > > > >                         var url = "
> > >http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/
> > > > > jquery.js";
> > > > >                         var head =
> > > document.getElementsByTagName("head")[0], done = false;
> > > > >                         var script =
> document.createElement("script");
> > > > >                         script.src = url;
> >
> > > > >                         script.onload = script.onreadystatechange =
> > > function() {
> >
> > > > There is no onload attribute for script elements defined in HTML
> 4.01,
> > > > therefore you should not expect that a script element will fire a
> load
> > > > event. The fact that some browsers do and some don't should be enough
> > > > to tell you that browser behaviour is inconsistent.  You are unlikely
> > > > to be able to reliably fix that with script.
> >
> > > > If you want a reliable indicator that a script has finished loading
> > > > and is ready for use, put a statement at the bottom like:
> >
> > > >   var SCRIPT_LOADED = true;
> >
> > > > --
> > > > Rob
>

Reply via email to