【问题标题】:Trapping ctrl+n key combination in chrome在 chrome 中捕获 ctrl+n 组合键
【发布时间】:2012-04-02 06:38:04
【问题描述】:

有没有办法在 chrome 中捕获 ctrl+n 键(通过使用 javascript、jquery 或任何插件)?我需要将 ctrl+n+enter 键分配给特定任务,但只要我按下 ctrl+ n,chrome 打开一个新窗口。我可以通过使用 ctrl+n 在 Firefox 中捕获:

event.preventDefault() 

但它在 chrome 中不起作用。

【问题讨论】:

  • “我可以使用 event.preventDefault() 在 Firefox 中捕获 ctrl+n,但它在 chrome 中不起作用。” 总是最好显示您的代码,但它是在这种情况下是学术性的:你不能这样做,请参阅 userD 指向的另一个问题。
  • 知道了...目前在 chrome 4 中是不可能的。

标签: javascript jquery


【解决方案1】:

这可能适用于您的问题。

// defining flags
var isCtrl = false;
var isShift = false;
$(document).ready(function () {
    // action on key up
    $(document).keyup(function (e) {
        if (e.which == 17) {
            isCtrl = false;
        }
        if (e.which == 16) {
            isShift = false;
        }
    });


   $(document).keydown(function (e) {
        if (e.which == 17) {
            isCtrl = true;
        }
        if (e.which == 16) {
            isShift = true;
        }

if ((e.which == 110 || e.which == 78) && isCtrl) {
            e.preventDefault(true);
}
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多