[Javascript] Keystroke event

Laurent Muchacho elmuchacho at gmail.com
Fri Mar 24 06:54:13 CST 2006


Hi Nick,

Yes this is what I thought originally and try this approach but with no
success.
I didn't know about the preventDefault method but this, neither seems to be
able to stop the default save as window to open.

Many thanks for your help

If anyone got an idea let it come :-)

function keyDown(e) {
    if(e.ctrlKey){
        document.onkeydown = trigger_ctrlS;
    }
}
function trigger_ctrlS(e){
    var keycode = e.which
    if(keycode==83){
        alert("ctrl s");
        return false
    }
}
document.onkeydown = keyDown

Laurent

On 3/24/06, Nick Fitzsimons <nick at nickfitz.co.uk> wrote:
>
> > 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/
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20060324/8b283b5a/attachment.htm>


More information about the Javascript mailing list