I'm trying to "detect" a keydown event in a DIV.
The idea have a keydown listener attached to document and forward the
event to the div. (I've searched the web, but it was impossible to
handle the noise on this topic.)
I've tried a simple prototype in Firefox and it seems to work.
function forward(e, elem) {
var f, p;
f = document.createEvent("Event");
f.initEvent(e.type, true, true);
for(p in e) {
if(typeof f[p] === "undefined") {
f[p] = e[p];
}
}
elem.dispatchEvent(f);
}
Three questions remain:
(a) is this whole approach crap?
(b) can keydown trigger a listener attached to the div directly (quite a
few oldish sources on google say so, I couldn't confirm that, and the
official mozilla documentation is rather sparse on that)?
(c) did I overlook something serious in my forward function?
Gregor