Andrew Arnott Andrew Arnott - 1 year ago 96
Javascript Question

How to handle ESC keydown on javascript popup window

I have a javascript popup, and I want the popup to close itself when the user presses the ESC key. I can't figure out how to hook the keydown event (and on what object?) so that I can catch the ESC key.

I'm using jQuery.

Answer Source

Try something like this:

$(document).keydown(function(e) {
    // ESCAPE key pressed
    if (e.keyCode == 27) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download