javascript - 使用 javascript 覆盖 chrome 默认快捷方式
问题描述
我有应用程序,我必须覆盖 chrome 浏览器的几个快捷键。我无法覆盖一些默认快捷键,但可以编写一些自定义快捷键来触发警报Stackblitz 示例。
这些是我要覆盖的新命令,
- CTRL+T
- CTRL+N
- CTRL+W
- CTRL+F4
- CTRL+TAB
- Alt+F4
有什么办法可以覆盖 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 :}" />
推荐阅读
- google-sheets - 在 Google 电子表格中转换带括号的电话号码
- php - Laravel 语言选择器
- regex - 在可选组之间获取组
- jquery - ASP.Net MVC ItextSharp:通过 jquery 调用操作时未下载 PDF 文件
- node.js - 猫鼬查询不返回实际对象
- c# - 当 ThreadUI 进入睡眠状态时,C# 在指定的 UIThread(不是延续)中运行任务会阻塞
- python - pandas:枚举每组中的项目
- javascript - 如何破坏缓存以便用户获取所有新的静态文件(例如 style.CSS、main.js)?
- java - Minimax 算法 - 当我有两种获胜方式时,计算机不会阻止我。
- python - `global` 是类访问模块级变量的正确方法吗?