A window/popup in web page can be provided with close (X) button at top-right corner to close that. How to make one closed with 'escape' key pressed?
Facebook chat boxes will be closed with the "esc" key pressed. How to do that?
Thanks.
It's totally depends on which window dialog/popup are you using. Because different dialog/popup can be handled by differently.
But you can use keyboard key press event(key code :27
) to detect when use clicked ESC
key.
Here is the example:
Suppose, you're using jquery dialog to show your content then you can handle ESC
key event.
$(document).keydown(function(e) {
// ESCAPE key pressed
if (e.keyCode == 27) {
window.close();
}
});
Hope this helps!