Disable Internet Explorer shortcut keys

前端 未结 6 784
臣服心动
臣服心动 2020-12-17 00:52

EDIT: After waited a while and didn\'t get anything yet, I\'ve decided to do shortcut disable thingy only for IE now. Is there a possib

6条回答
  •  旧巷少年郎
    2020-12-17 01:16

    Yes, you can listen for the various key combinations with javascript and disable the default behaviors. There's even a library that you can use and test here. I just tested it using google chrome and firefox in their demo textarea, and it works as you want.

    shortcut.add("Ctrl+P",function() {
        return;
    });
    

    This works in the browsers that I listed above, but IE will not allow you to override the default behavior in some cases.

    Your only option in IE is to disable the Ctrl key entirely with something like:

    document.onkeydown = function () { 
      if (event.keyCode == 17) alert('Ctrl Key is disabled'); 
    };
    

    Which is not ideal and probably not what you want, but it will work.

提交回复
热议问题