Re: Target of onkeyup/down/press events

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 UTC