How to handle ESC keydown on javascript popup window

前端 未结 8 670
孤独总比滥情好
孤独总比滥情好 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:29

    Remember that you must use the function @Gumbo posted in the popup-window... So you will need to include JQuery in the popup and execute the function there, not the window that opens the popup.

    0 讨论(0)
  • 2020-12-07 19:33

    To handle both esc and enter key on dialog window.onkeydown = function(event) {

    if(event.keyCode===27|| event.keyCode===13){
       window.close();
    }
    }
    
    0 讨论(0)
提交回复
热议问题