Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Keystroke event
- From: nick at nickfitz.co.uk (Nick Fitzsimons)
- Subject: [Javascript] Keystroke event
- Date: Fri Mar 24 05:42:35 2006
> Hi
>
> Does anyone know a good reference or have a nice examples to catch the
> keystroke ctrl+s in the browser
> I wrote this simple function but everytime the browser try to do a save.
>
<snip>
>
> function keyDown(e) {
> var keycode = e.which
> if(keycode==17){
> document.onkeydown = trigger_ctrlS;
> return true
> }
> }
> function trigger_ctrlS(e){
> var keycode = e.which
> if(keycode==83){
> alert("ctrl s: ")
> document.onkeydown = keyDown
> return true
> }
> }
> document.onkeydown = keyDown
The usual way of cancelling the default action for an event is to return
false from the event handler; try changing your "return true;" in the
above to "return false;" and see if that helps.
If that doesn't work, as you say it's for Firefox, try visiting the
Firefox/Mozilla developers site:
<http://developer.mozilla.org/en/docs/DOM:event#Introduction>
explains the "preventDefault" method, which might do what you want.
HTH,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
- Follow-Ups:
- [Javascript] Keystroke event
- From: Laurent Muchacho
- [Javascript] Keystroke event
- References:
- [Javascript] Keystroke event
- From: Laurent Muchacho
- [Javascript] Keystroke event
- Prev by Date: [Javascript] Keystroke event
- Next by Date: [Javascript] Keystroke event
- Previous by thread: [Javascript] Keystroke event
- Next by thread: [Javascript] Keystroke event
- Index(es):