W3C home > Mailing lists > Public > public-webapi@w3.org > December 2006

Re: capturing load events

From: Shadow2531 <shadow2531@gmail.com>
Date: Sun, 31 Dec 2006 03:54:29 -0500
Message-ID: <6b9c91b20612310054k7921e683s73a98ac665363072@mail.gmail.com>
To: "Bjoern Hoehrmann" <derhoermi@gmx.net>
Cc: "Hallvord R. M. Steen" <hallvord@opera.com>, public-webapi@w3.org, "Joao Eiras" <joao.eiras@gmail.com>

On 12/29/06, Bjoern Hoehrmann <derhoermi@gmx.net> wrote:
> * Shadow2531 wrote:
> >[...]
>
> Try this fragment:
>
>   <pre id='r'>&#xa;</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'>&#xa;</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 08:54:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:56 GMT