views:

844

answers:

1

I have a dialogue box which appears, and I would like it to be hidden again when you hit the escape key.

That all works fine in IE, Fx, Opera - the code registers a document.onkeypress event handler when the box is shown, then tests the event keyCode to see if it's the escape key or not (keyCode 27), but this doesn't seen to work in WebKit based browsers (Chrome and Safari (3) ), though other keys can be captured this way.

Do WebKit browsers not to trigger an event at all when escape is pressed?

Does anyone know why this doesn't work, how to fix it, or know of a work-around.

+4  A: 

Catch keydown/keyup instead. Take a look at this entry for more information.

Nicholas Riley
great link, thanks
PeterJCLaw
Thanks - I was using `keypress` with the same issue. Switched to `keyup` and it's working great now.
Greg K

related questions