所以我正在编写一个快捷方式库,并且在大多数情况下它都可以工作,除了我立即发现的问题是在 Chrome 中(因为我在 Chrome 书上所以没有测试过其他浏览器)是当按 ctrl+n 会创建一个新的浏览器窗口。基本上在 jist 中,我的代码检查是否定义了当前的键选择以及它是否是 preventDefault
并运行该命令的 exec
函数。
即。
if(joinedKeys in commands.cmd)
e.preventDefault();
commands.cmd[joinedKeys].exec();
我什至尝试过这样做-
document.addEventListener("keydown",function(e){
e.preventDefault();
});
//as well as window.addEvent...
都不起作用。关于停止浏览器的默认操作有什么建议吗?
最佳答案
参见https://stackoverflow.com/a/7296303/5298696
In Chrome4, certain control key combinations have been reserved for browser usage only and can no longer be intercepted by the client side JavaScript in the web page. These restrictions did not exist in Chrome3 and are inconsistent with both Firefox3/3.5 and IE7/8 (on Windows).
关于javascript - Chrome 中的快捷键命令不会阻止默认操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390157/