W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2009

Re: DOM3 Events call today/tonight?

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Wed, 25 Feb 2009 13:26:37 -0800
Message-ID: <c9e12660902251326w50b164edr7f98052ace6317de@mail.gmail.com>
To: Olli Pettay <Olli.Pettay@helsinki.fi>
Cc: WebApps WG <public-webapps@w3.org>
On Wed, Feb 25, 2009 at 10:16 AM, Olli Pettay <Olli.Pettay@helsinki.fi> wrote:
> On 2/25/09 7:46 PM, Garrett Smith wrote:
>>
>> On Wed, Feb 25, 2009 at 8:27 AM, Charles McCathieNevile
>> <chaals@opera.com>  wrote:
>>>
>>> Hi folks,
>>>
>>> unfortunately I have not been able to catch up with Doug (a combination
>>> of
>>> both of us travelling and then I had a minor accident that put me out of
>>> commission for a while), so as far as I know we have no agenda planned
>>> for
>>> tonight's call.
>>>
>>> The call is booked:
>>> Telephone: +1.617.761.6200  meeting code 3663 (DOM3).
>>> Pacific time: 11.30am - 1pm
>>> Boston time: 2.30pm - 4pm
>>> UTC: 1930Z - 2100Z
>>> CET: 2030 - 2200
>>>
>>> If anyone would like to hold a call, please reply to this thread - if
>>> there
>>> are no replies in the next 90 minutes (by 1900CET, 10am Pacific, 1pm
>>> Boston), we will postpone the restart until next week, and Doug and I
>>> will
>>> coordinate to ensure there is an agenda.
>>>
>>
>> It might be worth discussing the load event;
>> http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-load
>>
>> Seems that it is "specified" to fire on Document or Element (instead
>> of window).
>
>
> HTML 5 says that "If the Document is in a browsing context, then queue a
> task to fire a load  event at the Document's Window  object."
> And that is what at least Gecko does.
>
> 'load' is a special event in many ways. 'load' events dispatched somewhere
> in document (for example for <img>) don't propagate to 'window'. And the
> 'load' event which is dispatched to 'window', has 'document' as its target.
> This all is required for backwards compatibility.
>

I see.

window does implement EventTarget
. It has addEventListener, removeEventListener, and dispatchEvent. The
callback gets the |event| parameter.

In Webkit/Gecko, the |event.target| is document.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<title>load</title>
	<script type="text/javascript">
	window.addEventListener('load', function(ev) {
	  var m = document.getElementById('m');
	  m.firstChild.data = "this: " + this +
	          "\nev.target: " + ev.target +
	          "\nev.currentTarget: " + ev.currentTarget;
	}, false);
</script>
</head>
<body>
<pre id="m">Loading...</pre>
</body>
</html>


Results:
Opera
  this: [object Window]
  ev.target: [object Window]
  ev.currentTarget: [object Window]

Firefox:
  this: [object Window]
  ev.target: [object HTMLDocument]
  ev.currentTarget: [object Window]

Webkit:
  this: [object DOMWindow]
  ev.target: [object HTMLDocument]
  ev.currentTarget: null


> This is related to http://www.w3.org/2008/webapps/track/issues/44
>
>

I see Jonas' comment along the lines of "when we tried to implement it
this way, it broke sites"; Arguably, sites that expected event.target
to be document were already broken. Those sites were expecting
nonstandard behavior which does not work in Opera.

The other consideration is that adding a load event to document. Just
use the example above and change window.addEventListener to
document.addEventListener. The result is:

Webkit, Gecko: "Loading..."
Opera:
this: [object HTMLDocument]
ev.target: [object HTMLDocument]

Opera also (oddly) supports load event on document.body as an
intrinsic event. The target is also window.

<!DOCTYPE HTML>
<html lang="en">
<head>
	<title>body onload</title>
 </head>
<body>
<pre id="m">Loading...</pre>
	<script type="text/javascript">
	document.body.onload = function(ev) {
	  var m = document.getElementById('m');
	  m.firstChild.data = "this: " + this +
	          "\nev.target: " + ev.target;
	};
</script>
</body>
</html>

Opera:
this: [object Window]
ev.target: [object Window]

Opera also supports intrinsic load event on document. Change the
example above to |document.onload = function(ev) |.
Result in Opera:
this: [object HTMLDocument]
ev.target: [object HTMLDocument]

Interesting stuff. I wonder why Opera implemented that.

As an author, I would favor window.addEventListener. In the callback
would not expect anything of ev.target, but could expect |this ===
window|.

Garrett

[1]http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Registration-interfaces
Received on Wednesday, 25 February 2009 21:27:13 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:30 GMT