在浏览器中覆盖控件+ s(保存功能) [英] Overriding control+s (save functionality) in browser
问题描述
我试图覆盖浏览器保存快捷方式,即(cntrl + s)在我的网络应用程序中提供保存功能,我使用的是谷歌浏览器...我试过keydown listner来观察密钥代码但是当两个密钥即同时按下(cntrl + s),s的键代码永远不会在事件对象中返回。
I am trying to override the browser save shortcut i.e(cntrl + s) to give the functionality of save in my web App , I am using google chrome ... I tried keydown listner to observe the keycode but when two keys i.e (cntrl + s) are pressed simultaneously , keycode of s is never returned in event object .
提前致谢
Trax
推荐答案
您收到两个keydown事件:第一个用于控制键,第二个用于打开修饰符标志的字母。以下是按下修饰符的方式来监听键的方法:
You receive two keydown events: The first is for the control key, and the second is for the letter with the modifier flag turned on. Here's how you listen for a key with a modifier pressed:
document.addEventListener("keydown", function(e) {
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
// Process event...
}
}, false);
从Google文档中获取页面,它在Mac上使用Cmd-S,在其他平台上使用Ctrl-S 。
Taking a page from Google Docs, it uses Cmd-S on Mac and Ctrl-S on other platforms.
这篇关于在浏览器中覆盖控件+ s(保存功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!