覆盖浏览器的键盘快捷键 [英] Overriding Browser's Keyboard Shortcuts
问题描述
我想通过截取文档对象的keypress事件处理程序而不是accesskey属性,在我的Web应用程序中添加对键盘快捷键的支持。
I'd like to add support for keyboard shortcuts to a couple of pages in my web application by intercepting the keypress event handler of the document object, not the accesskey attribute.
问题在于每个浏览器都有自己的键盘组合,所以不可能想出一套适用于所有网络浏览器且又一致的键盘组合。(例如,如果保存的快捷方式是愚蠢的话 Ctrl + Shift + S ,其中一个用于删除 Alt + D 。)
The problem is that every browser has its own keyboard combinations, so it's impossible to come up with a set of keyboard combinations that work on all web browsers and yet consistent.(e.g. It'd be silly if the shortcut for save was Ctrl + Shift + S while one for delete was Alt + D.)
所以我认为在我的几页中完全覆盖浏览器快捷方式会更简单。
So I figured it would be just simpler to override browser shortcuts altogether in a couple of pages with mine.
除了所有缺点,是否可能?如果是这样,你是怎么做到的?
All downside aside, is it possible? If so, how do you do it?
推荐答案
这里有一个很好的报道: http://unixpapa.com/js/key.html
There's an excellent coverage of this here: http://unixpapa.com/js/key.html
As对于是否应该这样做,stackoverflow的问题编辑器会覆盖相当多的键而不会中断太多(将鼠标悬停在工具栏按钮上)。
As for whether this is something that should be done, stackoverflow's question editor override's quite a few keys without disrupting too much (hover over the toolbar buttons).
这篇关于覆盖浏览器的键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!