I have a javascript window.open 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 wha
No more arbitrary number codes!
document.addEventListener('keydown', function(event) { const key = event.key; // const {key} = event; in ES6+ if (key === "Escape") { window.close(); } });
Mozilla Docs
Supported Browsers