R
runner7
Can anyone help me with how to programmatically fire a keydown event in
Firefox?
Firefox?
runner7 said:Can anyone help me with how to programmatically fire a keydown event in
Firefox?
runner7 said:As best as I can tell from "developer.mozilla" and "w3c" sites, the
following code should work in Firefox, but I cannot get it to work:
function keyFire(e) {
var e1=document.createEvent("KeyboardEvent");
e1.initKeyboardEvent("keydown",true,true,window,"U+0009",
DOM_KEY_LOCATION_STANDARD,null);
document.forms[0].elements[0].dispatchEvent(e1);
e.preventDefault();
e.stopPropagation();
}
"U+0009" happens to be for the tab key. Has anyone got a clue?
runner7 said:Thanks guys for your answers, but I think I need to clarify what I am
trying to do. I am not trying to detect a keystroke or what key was
pressed. I am trying to programmatically send the equivalent of a
keystroke to the Firefox browser.
In IE, the problem is trivial, because window.event.keyCode can be set,
but in Firefox the event.which property appears to be read only.
Bart said:I don't think this is correct. AFAIK, keyCode should be read-only
too.
Your problem is more fundamental. You want to make javascript think the
user pressed a key, while he actually didn't press it. It's spoofing by
definition - browsers are right to complain about this kind of
trickery. My gut feeling is that you should give up your plan and
rethink your coding strategy.
And honestly I can't think of any good reason why you would want to
fake a keystroke, besides theoretical or hacking motives.
runner7 said:Bart Van der Donck wrote:
The purpose is for a data entry application, such as when
using the numeric keypad to enter data. Typically, the
"enter" key will work like a "tab" key until the last
field on the form.
Using String.fromCharCode(9) to append to the fields's
value only appends a "tab" character just like in a
word processing application, but does not cause the cursor
to move to the next field. Any ideas on how to
make "enter" work like "tab" in Firefox?
runner7 said:Richard Cornford wrote:
Is that typical of web browsers? That has not been my experience.
Richard said:That can certainly be done (on the
limited number of browsers you seem interested in) by identifying the
significant key event, cancelling it, identifying the next filed and
explicitly calling its - focus - method.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.