简体   繁体   English

停止事件冒泡到 Chrome 浏览器以进行 alt-keypress

[英]Stop event bubbling to Chrome browser for alt-keypress

(Encountered while writing this script ) (写这个脚本时遇到的)

Relevant code:相关代码:

window.keyPressEventLambda=function(key,callback){ //just a lambda function wrapper so I can generate handlers on the fly
return function (zEvent) {
        if (zEvent.altKey  && ( zEvent.which == key.charCodeAt(0)||zEvent.which == key.toUpperCase().charCodeAt(0))) {
            callback(this.id);
            return false;
        }
        return true;
}
}

Use case:用例:

$("textarea").live("keydown",keyPressEventLambda("C",function(id){/*blah blah blah */})

So, if I use Alt - C , the callback function runs itself.因此,如果我使用Alt - C ,回调函数会自行运行。

Now, due to the return false;现在,由于return false; , bubbling is suppressed and everything is handy-dandy within the page itself. ,冒泡被抑制,页面本身的所有内容都非常方便。

But, Chrome (20.0.1128.0 or 19.0.1084.41 on Windows), still captures the alt key as a Chrome browser shortcut, and, since no shortcut actually exists for Alt - C , it fails and makes an annoying "ping" sound.但是,Chrome(Windows 上的 20.0.1128.0 或 19.0.1084.41)仍将 alt 键捕获为 Chrome 浏览器快捷方式,并且由于Alt - C实际不存在快捷方式,因此它失败并发出恼人的“ping”声音。

It works fine for Ctrl -shortcuts, but I don't want to use these since most of the Ctrl -shortcuts are taken.它适用于Ctrl -shortcuts,但我不想使用这些,因为大多数Ctrl -shortcuts 都被占用了。

Is there any way to prevent the browser from getting angry at my script?有什么办法可以防止浏览器对我的脚本生气?

This is a known Chrome-issue.这是一个已知的 Chrome 问题。 See http://code.google.com/p/chromium/issues/detail?id=105500请参阅http://code.google.com/p/chromium/issues/detail?id=105500

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM