S
Safalra
Recently I've rewritten much of my old Javascript code to use DOM functions
so that enhancements can be attached to documents without needing to alter
the HTML code. I assumed that adding event handlers to document.body would
have the same effect as adding those event handlers through attributes of
the body element, but this turned out not to be the case for key events.
Take this example page (IE-specific code removed):
http://www.safalra.com/hotlinkable/key-events.html
Key events will highlight the appropriate table cells in red for a quarter
of a second. It turns out the the DOM equivalent of adding key event
handlers to the body element is to add them to the document object, not
document.body. If the event handler is added to document.body, key events
are only detected for subelements (try typing in the input box).
Is Firefox' behaviour correct, and if so why?
so that enhancements can be attached to documents without needing to alter
the HTML code. I assumed that adding event handlers to document.body would
have the same effect as adding those event handlers through attributes of
the body element, but this turned out not to be the case for key events.
Take this example page (IE-specific code removed):
http://www.safalra.com/hotlinkable/key-events.html
Key events will highlight the appropriate table cells in red for a quarter
of a second. It turns out the the DOM equivalent of adding key event
handlers to the body element is to add them to the document object, not
document.body. If the event handler is added to document.body, key events
are only detected for subelements (try typing in the input box).
Is Firefox' behaviour correct, and if so why?