When solving the problem of adding keyboard shortcuts to your web application, I was faced with the fact that many "good" keyboard shortcuts are already occupied by the browser. But the worst thing is that every browser has its own shortcut keys.

In principle, the answer "With this you can not do anything. JavaScript can not interfere with the browser settings" is quite predictable. But how are they struggling with this problem in other applications?

    1 answer 1

    It's simple:
    Assign and catch what you need, and the browser can be told not to do it (set the focus on the snippet page to enter the keys there):

    document.addEventListener('keydown', function(e){ if(e.ctrlKey && e.keyCode === 83){ // Ctrl + s, браузерное сочетание e.preventDefault(); // Отменяем действие браузера console.info("Сохранить страницу, юнец, не позволю тебе я!"); } }); 

    Mana by Event.preventDefault .

    I also note that some actions cannot be undone, since their "owner" is the OS, not the browser:
    Alt + F4 , Ctrl + Shift + Esc , etc.

    • Ctrl+Shift+S could not be undone for Chrome - Gleb
    • @GurebuBokofu, so in chrome "Save As" is Ctrl + S And Ctrl + Shift + S does nothing at all. - user207618
    • Sealed :) Crtl+Shift+T did not work. I set Ctrl+T and Ctrl+Shift+T e.preventDefault(); , but all the same, both actions work ... - Bokov Gleb
    • @GurebuBokofu, this combination refers to the browser, not the page, so the cancellation does not work. However, chromium extensions can override even such combinations. - user207618
    • Clearly, in general, the limit of possibilities is here :) Even if we can access the extension from the code, we need to force the user to install this extension, and it will only work in Chrome. Did I say everything correctly? - Bokov Gleb