listen to 'CTRL+N' with javascript
问题 I am trying to bind the 'CTRL+N' key combination, like this: var ctrlPressed = false; var nCode = 78; var ctrlCode = 224; var cmdCode = 17; document.addEventListener ("keydown", function(e){ if( e.keyCode == ctrlCode || e.keyCode == cmdCode){ ctrlPressed = true; }else{ ctrlPressed = false; } console.log(e.keyCode); }); document.addEventListener ("keyup", function(e){ if(ctrlPressed && e.keyCode == nCode){ e.preventDefault(); nou_element(parent); return; } }); Please note: jQuery isn't