- From: Joćo Eiras <joao.eiras@gmail.com>
- Date: Sun, 31 Dec 2006 19:06:18 +0000
- To: Shadow2531 <shadow2531@gmail.com>
- Cc: "Bjoern Hoehrmann" <derhoermi@gmx.net>, "Hallvord R. M. Steen" <hallvord@opera.com>, public-webapi@w3.org
> So, my question is, what's the reason for not wanting win t+b(2) to fire? The load event doesn't bubble, so it fires with the Document as target, and doesn't go up. But compatibility with the current web demands this. 2006/12/31, Shadow2531 <shadow2531@gmail.com>: > On 12/29/06, Bjoern Hoehrmann <derhoermi@gmx.net> wrote: > > * Shadow2531 wrote: > > >[...] > > > > Try this fragment: > > > > <pre id='r'>
</pre> > > <script> > > function trace(s) > > {document.getElementById('r').firstChild.nodeValue+=s+"\n";} > > window.addEventListener('load',function(e){ > > trace("win cap ("+e.eventPhase+") ("+e.target+")")}, true); > > document.addEventListener('load',function(e){ > > trace("doc cap ("+e.eventPhase+") ("+e.target+")")}, true); > > document.addEventListener('load',function(e){ > > trace("doc t+b ("+e.eventPhase+") ("+e.target+")")}, false); > > window.addEventListener('load',function(e){ > > trace("win t+b ("+e.eventPhase+") ("+e.target+")")}, false); > > </script> > > <p><img alt='' src='http://www.w3.org/Icons/valid-xhtml10' /></p> > > > > If you simply consider the window to be a parent of the Document, that > > the load event does not bubble, and the load event is dispatched to the > > img element first, then to the document, the correct result would be: > > > > win cap (1) ([object HTMLImageElement]) > > doc cap (1) ([object HTMLImageElement]) > > win cap (1) ([object HTMLDocument]) > > doc t+b (2) ([object HTMLDocument]) > > O.K. Try the following in Opera if you would. > > <pre id='r'>
</pre> > <script> > function trace(s){ > document.getElementById('r').firstChild.nodeValue+=s+"\n"; > } > /*capture window descendant load events*/ > window.addEventListener('load',function(e){ > var t=e.target; > if (t==document.body) { > /*In Opera, simulate document as target instead of body*/ > t=document; > } > trace("win cap ("+e.eventPhase+") ("+t+")"); > },true); > /*capture document descendant load events*/ > document.addEventListener('load',function(e){ > /*In Opera, simulate document as target instead of body*/ > if (e.target!=document.body) { > trace("doc cap ("+e.eventPhase+") ("+e.target+")"); > } > },true); > document.addEventListener('load',function(e){ > trace("doc t+b ("+e.eventPhase+") ("+e.target+")"); > },false); > window.addEventListener('load',function(e){ > trace("win t+b ("+e.eventPhase+") ("+e.target+")"); > },false); > </script> > <p><img alt='' src='http://www.w3.org/Icons/valid-xhtml10' /></p> > > That should produce: > > win cap (1) ([object HTMLImageElement]) > doc cap (1) ([object HTMLImageElement]) > win cap (1) ([object HTMLDocument]) > doc t+b (2) ([object HTMLDocument]) > win t+b (2) ([object HTMLDocument]) > > That's everything you expect except for the win t+b (2) at the end. > > So, my question is, what's the reason for not wanting win t+b(2) to > fire? Is it because win cap (1) already fires a load for the Document > and you don't want a second one firing? > > If so, then I assume if you get rid of the window capturing listener, > then you'd want win t+b(2) to fire as usual? > > In other words, it sounds like you're saying, > window.addEventListener("load", func, true) should override > window.addEventListener("load", func, false). > > Thanks > > -- > burnout426 >
Received on Sunday, 31 December 2006 19:06:24 UTC