How to handle ESC keydown on javascript popup window

前端 未结 8 716
孤独总比滥情好
孤独总比滥情好 2020-12-07 19:03

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

8条回答
  •  佛祖请我去吃肉
    2020-12-07 19:09

    It is possible to achieve with JS Without using jQuery.

    window.onkeydown = function( event ) {
        if ( event.keyCode == 27 ) {
            console.log( 'escape pressed' );
        }
    };
    

提交回复
热议问题