【问题标题】:Override the chrome default shortcuts using javascript使用 javascript 覆盖 chrome 默认快捷方式
【发布时间】:2021-02-02 12:21:29
【问题描述】:

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

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

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

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

【问题讨论】:

  • 实际上,嗯..那些特定的命令.. ight
  • 哇.. javascript 让我们听键盘的唯一方法.. 事件发生了.. 但我认为 preventDefault 不能应用于它>:{ 这是个好问题跨度>

标签: javascript html google-chrome


【解决方案1】:

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

【讨论】:

  • 这对我不起作用,你能给我工作的 sn-p 吗,否则你可以编辑上面的例子。
  • 你至少不能复制、粘贴、剪切或全选
  • @Santhosh 对于其他事情.. 我不确定他们可以停止 :shrugs:
猜你喜欢
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-14
  • 2017-09-01
  • 2021-10-08
  • 2014-05-04
  • 1970-01-01
相关资源
最近更新 更多