W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2011

Re: Target of onkeyup/down/press events

From: Giuseppe Pascale <giuseppep@opera.com>
Date: Thu, 12 May 2011 17:56:05 +0200
To: "Olli Pettay" <Olli.Pettay@helsinki.fi>, Olli@pettay.fi
Cc: "www-dom@w3.org" <www-dom@w3.org>
Message-ID: <op.vvdk7rrm6ugkrk@rabdomant-ubuntu>
On Thu, 12 May 2011 16:55:52 +0200, Olli Pettay <Olli.Pettay@helsinki.fi>  
wrote:
> Your test doesn't test event targeting.
> Of course events propagate up to the document, but the question
> is are there cases when key events can be dispatched to document
> so that event.target == document.
>

Actually I wanted to test both (maybe it was obvious that the event "at  
least" propagates but you never know).

Anyway you are right, we should try to come up with a test that targets a  
document.

Using the test below and printing the event target and currentTarget I get  
interesting results:

FF says the target is an "HTMLHtmlElement" and the currentTarget is  
"HTMLDocument"
Opera and Chrome says that the target is an "HTMLBodyElement" and the  
currentTarget is "HTMLDocument"

/g

>
>
>>
>>
>> <html>
>> <head>
>> <script type="text/javascript">
>>
>> function testEvent(){
>> document.onkeyup=my_keyup;
>> document.onkeydown=my_keydown;
>> document.onkeypress=my_keypress;
>> }
>>
>> function my_keyup(){
>> alert('keyup');
>> }
>>
>> function my_keydown(){
>> alert('keydown');
>> }
>>
>> function my_keypress(){
>> alert('keypress');
>> }
>>
>> </script>
>> </head>
>> <body onload="testEvent()">
>> document.keyXXX event test
>> </body>
>> </html>
>>
>> Even though to be honest keyup event doesn't seem to be delivered (in
>> Opera, Chrome and FF). I didn't do any extensive testing with different
>> versions or OSes.
>>
>> /g


-- 
Giuseppe Pascale
TV & Connected Devices
Opera Software - Sweden
Received on Thursday, 12 May 2011 15:56:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:07 GMT