首页 > 解决方案 > 使用 javascript 覆盖 chrome 默认快捷方式

问题描述

我有应用程序,我必须覆盖 chrome 浏览器的几个快捷键。我无法覆盖一些默认快捷键,但可以编写一些自定义快捷键来触发警报Stackblitz 示例

这些是我要覆盖的新命令,

有什么办法可以覆盖 chrome 默认快捷键。

标签: javascripthtmlgoogle-chrome

解决方案


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 :}" />


推荐阅读