Override the chrome default shortcuts using javascript

Viewed 412

I have application where I have to override few shortcuts keys of the chrome browser. I am not able to override few of the default shortkeys but can write few custom shortkeys to trigger a alert Stackblitz example.

these are the new commands I want to override ,

  • CTRL+T
  • CTRL+N
  • CTRL+W
  • CTRL+F4
  • CTRL+TAB
  • Alt+F4

Is there any way I can override the chrome default shortcut keys.

1 Answers

document.addEventListener('keydown',
function(ev){
  //I just can't stop alt-F4 and CTRL-W though, think they are overrides you can't change, but for ones you can change, this works
  if(ev.ctrlKey||ev.altKey){ev.preventDefault()}
}
)
<input placeholder="try copying/cutting/pasting :}" />

Related