Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Internet Explorer shortcut keys

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 possibility to disable IE shortcut keys to access menus/print etc. via vbscript?

Is it possible to disable browser shortkeys?

Because many of them are using in application. For instance, Ctrl+p is using and I don't want browser to popup the print window.

like image 706
Ramiz Uddin Avatar asked Jul 15 '09 09:07

Ramiz Uddin


People also ask

How do I disable shortcut keys?

Navigate to User Configuration > Administrative Templates > Windows Components > File Explorer. Double-click on the Turn off Windows Key Hotkeys option on the right-hand side.

How do I disable CTRL O in Internet Explorer?

To disable the restriction, set the value to 0. NoFileOpen Disables Open command on File menu, CTRL+O, and CTRL+L.


3 Answers

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.

like image 143
Keith Bentrup Avatar answered Oct 22 '22 22:10

Keith Bentrup


You can try creating an event handler for keydown event, check on the keyCode and prevent its default action if needed. However this will not work in all browsers.

An example for Firefox (canceling "Print" short key, verified):

document.addEventListener("keydown", function(oEvent) {
    if (oEvent.keyCode == 80 && oEvent.ctrlKey)
        oEvent.preventDefault();
}, false)
like image 27
Sergey Ilinsky Avatar answered Oct 22 '22 22:10

Sergey Ilinsky


There is a nice trick to fight with IE10+, to avoid display browser menus on alt key combinations, like Alt + F, Alt + H ...

I recently used on IE11, just add an anchor with the attribute accesskey:[yourKey] on your body

<body>
   <a href="#" accesskey="f"></a>
   <script type="text/javascript">
    window.onkeydown = function(e){
          console.log(e.keyCode + " alt: " + e.altKey);
          e.preventDefault();
    };
    window.onkeyup = function(e){
          console.log(e.keyCode + " alt: " + e.altKey);
          e.preventDefault();
    };
   </script>
</body>

Now when you press Alt + f the browser will not display "File popup" as usual, and will let events keydown and keyup gets to you, and not only keydown.

like image 32
sendler Avatar answered Oct 22 '22 23:10

sendler