From: Andrew Poulos on 23 Nov 2009 18:07 Matt Kruse wrote: > On Nov 23, 1:46 pm, Stevo <n...(a)mail.invalid> wrote: >> Shame there was no resolution to this. I was hoping for an answer to it >> also. Instead of focusing on the question (the second paragraph above) >> all the answers disregarded it. > > Typical of this group, which is why it's become mostly irrelevant. Maybe for you but not for me. Andrew Poulos
From: RobG on 23 Nov 2009 19:48 On Nov 24, 5:46 am, Stevo <n...(a)mail.invalid> wrote: > Matt Kruse wrote: > > There is a discussion going on in the jquery-dev mailing list that > > piqued my curiosity. I'm interested to know if the smart people here > > have a good answer. > > > Is there a cross-browser way, in script, to determine if window.onload > > has already fired? > > > If a script is lazy loaded and needs the DOM to be ready, it can > > attach to the window's load event. But if that has already fired, then > > the script's code will never run. Alternatively, it can just fire its > > code inline, but the DOM may not be ready. > > > Thoughts? > > > Matt Kruse > > Shame there was no resolution to this. There was a resolution. > I was hoping for an answer to it > also. There was. > Instead of focusing on the question (the second paragraph above) > all the answers disregarded it. There were two answers that focussed specifically on the question and provided two approaches. > I guess there is no way to find out if it's fired using regular DOM methods. You got it, but that wasn't the question. There was no specific mention of a DOM method, but that doesn't mean there aren't strategies for determining if it's occurred. -- Rob
From: David Mark on 23 Nov 2009 21:15 Matt Kruse wrote: > On Nov 23, 1:46 pm, Stevo <n...(a)mail.invalid> wrote: > > Shame there was no resolution to this. I was hoping for an answer to it > > also. Instead of focusing on the question (the second paragraph above) > > all the answers disregarded it. > > Typical of this group, which is why it's become mostly irrelevant. Typical of your petulance and incompetence, you can't see the forest for the trees. Clearly you came into this fact-finding mission with a negative attitude (as usual). > > > I guess there is no way to find out if it's fired using regular DOM methods. > > It doesn't appear so. Then you are blind. There must be some script that downloads the secondary code. So that script sets an onload listener that sets a "loaded" flag. The other scripts refer to that flag. End of story. > > Or to phrase it differently, a script that is executing after the > firing of window.onload has no independent way of determining that it > has already fired. No kidding. You should have put it that way to start with. ;)
From: Matt Kruse on 23 Nov 2009 23:12 On Nov 23, 8:15 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > Then you are blind. There must be some script that downloads the > secondary code. So that script sets an onload listener that sets a > "loaded" flag. The other scripts refer to that flag. End of story. 1) That depends on the first script setting an onload listener. What if it is loaded after window.onload? 2) This strategy assumes you can modify the source of the second script. Matt Kruse
From: Stevo on 24 Nov 2009 00:38
Matt Kruse wrote: > On Nov 23, 8:15 pm, David Mark <dmark.cins...(a)gmail.com> wrote: >> Then you are blind. There must be some script that downloads the >> secondary code. So that script sets an onload listener that sets a >> "loaded" flag. The other scripts refer to that flag. End of story. > > 1) That depends on the first script setting an onload listener. What > if it is loaded after window.onload? > > 2) This strategy assumes you can modify the source of the second > script. > > Matt Kruse All it would take is for the browser to set window.onload = true after it's called all registered onload handlers, and those of us who want to know if it's already happened can check if(window.onload === true). I wish one of them would take the lead. The DOMContentLoaded event was a start in a related direction, but still we have no simple properties that let script determine whether onload has triggered, and/or whether the DOM is ready for full scripting. To further explain what Matt and I are both looking for, here's an example. Site A decides to load library script B at some point during the viewing of a page. It's completely unknown when this might be. They might be doing it in the head section, in the body section, or on-demand well after the onload event has fired because of some user action. Script B wants to know into which page state it's being loaded. Whether or not the event has fired already. Question: How can script B know if onload has fired without putting demands on site A to have to set flags (because the browser itself doesn't seem to want to). |