Re: [whatwg] events when navigating away before page load?
On 12/15/2012 01:52 AM, Ian Hickson wrote: On Sat, 15 Dec 2012, Olli Pettay wrote: There are also pageshow and pagehide events, although the spec for them seems to be wrong. They are fired always, not only when dealing with session history. Do you have a test case that shows when they are fired in a way that doesn't match the spec? (Note that session history is invoked when you load a page, and that pagehide is fired in the unload algorithm as well.) Ah, then I misinterpreted the spec.
Re: [whatwg] events when navigating away before page load?
On Sat, 15 Dec 2012, Olli Pettay wrote: > > There are also pageshow and pagehide events, although the spec for them > seems to be wrong. They are fired always, not only when dealing with > session history. Do you have a test case that shows when they are fired in a way that doesn't match the spec? (Note that session history is invoked when you load a page, and that pagehide is fired in the unload algorithm as well.) -- Ian Hickson U+1047E)\._.,--,'``.fL http://ln.hixie.ch/ U+263A/, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
Re: [whatwg] events when navigating away before page load?
There are also pageshow and pagehide events, although the spec for them seems to be wrong. They are fired always, not only when dealing with session history. -Olli On 12/14/2012 08:51 PM, Mike Wilson wrote: Thanks Ian, Ian Hickson wrote on 14 december 2012 19:22: On Fri, 14 Dec 2012, Mike Wilson wrote: What events are supposed to be fired when the browsing context gets navigated away before the current page has finished loading, ie before the load event has been fired? It's pretty complicated, but the short answer is "beforeunload" and "unload". "DOMContentLoaded" and "load" don't fire per spec, though this is controversial (it's been suggested that the abort that happens during navigation should be equivalent to the abort that happens when the user hits "Stop"; whether it is or not changes whether or not we pretend that the page finished parsing or not). I added the beforeunload event in an updated fiddle: http://jsfiddle.net/khwtB/ which resulted in: FF17 Chr23 IE9 spec - - - - domload y y n n load n n n n beforeunload y n y y unload​ y y n y So yes, it seems there is a lack of agreement here :-) Anyway, the finding that originally got me started on looking at this was that I received an unload event without a preceeding load event. Naively this seems logically wrong, but I appreciate these are complicated matters so I'm content with the answer that this probably shouldn't be expected in these kinds of cases. Best regards Mike
Re: [whatwg] events when navigating away before page load?
Ian Hickson wrote on 14 december 2012 21:11: > > As a general rule, the intent of the spec is that you > get a "load" when all your scripts (and other resources) > have loaded, and you get an "unload" when the page is > going away. Thus if the page goes away before the page > has finished loading, you just get an "unload". Yes, when I think about this a bit more it makes a lot of sense. Initially I did expect a behaviour more like abort/stop - skipping all outstanding i/o and "fast- forwarding" to the firing of the load event(s). But as you say, as we are leaving the page anyway, there shouldn't be a big need to do page load initializations. And a smart page can actually detect it's being rushed through by looking for unload without load. Note to self and to other page authors: make sure unload handlers don't break if related code in load handlers weren't executed. > We additionally also suggest firing a "load" and so forth > when the user aborts the page, on the assumption that you > probably have all the scripts you need and are only > missing minor things like ads or analytics Makes sense too - the user probably stopped the page when it seemed complete enough to him, so he should get event handlers and all other UI stuff set up that's normally in load handlers. I did a few more tests and found even more differences. Chrome has different behaviour depending on if the navigation is initiated while parsing or , and for the latter it fires the same events as Firefox although in a different order: FF17 Chr23 Chr23 IE9spec nav head nav head nav body nav head nav head or body or bodyor body -- -- -- -- -- beforeunld domloaddomloadbeforeunld beforeunld domloadunload beforeunldunload unloadunload Interesting stuff indeed :-) Best regards Mike
Re: [whatwg] events when navigating away before page load?
On Fri, 14 Dec 2012, Mike Wilson wrote: > > Anyway, the finding that originally got me started on looking at this > was that I received an unload event without a preceeding load event. > Naively this seems logically wrong, but I appreciate these are > complicated matters so I'm content with the answer that this probably > shouldn't be expected in these kinds of cases. Yeah, this whole area is rather gnarly. As a general rule, the intent of the spec is that you get a "load" when all your scripts (and other resources) have loaded, and you get an "unload" when the page is going away. Thus if the page goes away before the page has finished loading, you just get an "unload". We additionally also suggest firing a "load" and so forth when the user aborts the page, on the assumption that you probably have all the scripts you need and are only missing minor things like ads or analytics, but that doesn't apply when the page is aborted because another page is going to replace it. -- Ian Hickson U+1047E)\._.,--,'``.fL http://ln.hixie.ch/ U+263A/, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
Re: [whatwg] events when navigating away before page load?
Thanks Ian, Ian Hickson wrote on 14 december 2012 19:22: > On Fri, 14 Dec 2012, Mike Wilson wrote: > > > > What events are supposed to be fired when the browsing context > > gets navigated away before the current page has finished > > loading, ie before the load event has been fired? > > It's pretty complicated, but the short answer is "beforeunload" > and "unload". "DOMContentLoaded" and "load" don't fire per spec, > though this is controversial (it's been suggested that the abort > that happens during navigation should be equivalent to the abort > that happens when the user hits "Stop"; whether it is or not > changes whether or not we pretend that the page finished parsing > or not). I added the beforeunload event in an updated fiddle: http://jsfiddle.net/khwtB/ which resulted in: FF17 Chr23 IE9 spec - - - - domload y y n n load n n n n beforeunload y n y y unload​ y y n y So yes, it seems there is a lack of agreement here :-) Anyway, the finding that originally got me started on looking at this was that I received an unload event without a preceeding load event. Naively this seems logically wrong, but I appreciate these are complicated matters so I'm content with the answer that this probably shouldn't be expected in these kinds of cases. Best regards Mike
Re: [whatwg] events when navigating away before page load?
On Fri, 14 Dec 2012, Mike Wilson wrote: > > What events are supposed to be fired when the browsing context gets > navigated away before the current page has finished loading, ie before > the load event has been fired? It's pretty complicated, but the short answer is "beforeunload" and "unload". "DOMContentLoaded" and "load" don't fire per spec, though this is controversial (it's been suggested that the abort that happens during navigation should be equivalent to the abort that happens when the user hits "Stop"; whether it is or not changes whether or not we pretend that the page finished parsing or not). -- Ian Hickson U+1047E)\._.,--,'``.fL http://ln.hixie.ch/ U+263A/, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'