有没有办法覆盖Ctrl + N在Chrome中打开一个新窗口? [英] Any way to override Ctrl+N to open a new window in Chrome?

查看:175
本文介绍了有没有办法覆盖Ctrl + N在Chrome中打开一个新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网络应用程序进行工作,我经常使用的其中一个快捷方式是 Ctrl + M 。但是,我经常打字非常快,错误地点击 Ctrl + N ,而不是在我的网络应用程序中触发操作,我打开一个新窗口。我希望能够阻止这一点,但我似乎无法弄清楚如何。到目前为止,我已经尝试每次加载页面时都运行此代码,但它似乎没有做任何事情。 (忽略我只使用一个开关只有一个键的事实,我还有一些其他自定义的 Ctrl 快捷键,它们不会覆盖正在运行的Chrome快捷键,我只是为了便于阅读而删除了它们)

I use a web app for work, and one of the shortcuts I use often is Ctrl+M. However, I'm often typing very quickly and mistakenly hit Ctrl+N by mistake, and instead of triggering an action in my web app, I open up a new window. I would like to be able to prevent that, but I can't seem to figure out how. So far I've tried running this code every time the page loads, but it doesn't seem to do anything. (Ignore the fact that I'm using a switch for just one key, I have a few other custom Ctrl shortcuts that don't override Chrome shortcuts that are working, I just removed them for readability)

document.onkeydown = function(e) 
{
    if(e.ctrlKey === false)
    {
        return;
    }

    switch(e.which) {
        case 78:
            //just to keep from opening a new tab when merging cells
            e.preventDefault();
            e.stopPropagation();
            break;
        default: 
        return;
    }
};


推荐答案

无法覆盖 Ctrl + N Ctrl + T ,或 Ctrl + W in谷歌浏览器自Chrome第4版(2010年发售)以来。

There is no way to override Ctrl+N, Ctrl+T, or Ctrl+W in Google Chrome since version 4 of Chrome (shipped in 2010).

Chromium问题跟踪器


在Chrome4中,某些控制键组合仅保留用于浏览器使用,不能再使用被网页中的客户端JavaScript拦截。

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.

只有已知的解决方法是将您的网页/扩展程序打开为Chrome应用它将再次获得覆盖这些列入黑名单的密钥组合的许可

Only known workaround is to open your webpage/extension as a Chrome app where it will again have permission to override these blacklisted key combos

这篇关于有没有办法覆盖Ctrl + N在Chrome中打开一个新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆