Disable Internet Explorer keyboard shortcuts

EDIT: After a long wait and havenโ€™t received anything yet, I decided to make a shortcut to disable thingy only for IE now. Is it possible to disable IE Shortcuts for menu / print access, etc. through vbscript?

Can I disable browser shortcuts?

Because many of them are used in the application. For example, Ctrl + p is used , and I do not want the browser to pop up in the print window. A.

+6
javascript internet-explorer vb6 vbscript activex
source share
6 answers

Yes, you can listen to various keyboard shortcuts using javascript and disable the default behavior. There is even a library that you can use and test here . I just tested it with google chrome and firefox in my demo file and it works as you wish.

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

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

The only option in IE is to completely disable the Ctrl key, for example:

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

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

+4
source share

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

Example for Firefox (canceling the Print shortcut, confirmed):

 document.addEventListener("keydown", function(oEvent) { if (oEvent.keyCode == 80 && oEvent.ctrlKey) oEvent.preventDefault(); }, false) 
+3
source share

There is a good trick to fight with IE10 + in order to avoid displaying the browser menu on alt key combinations, for example Alt + F , Alt + H ...

I recently used in IE11, just add a binding with the accesskey attribute: [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 a โ€œpop-up windowโ€ as usual, and will allow you to launch a key case and keyup, not just a shutdown.

+2
source share

I am working on a similar problem, I connect a keyboard event . The below code works well to disable, except that the flash object in IE did not receive focus. Since I'm trying to handle a keyboard event on a flash object, this code does not work for me.

 function hookKeyboardEvents(e) { // get key code var key_code = (window.event) ? event.keyCode : e.which; // case :if it is IE event if (window.event) { if (!event.shiftKey && !event.ctrlKey) { window.event.returnValue = null; event.keyCode = 0; } } // case: if it is firefox event else e.preventDefault(); } window.document.onkeydown = hookKeyboardEvents; 
+1
source share

From your application, after calling the method on Ctrl + P, just enter the key code as zero.I think it will solve your problem ...

window.event.keyCode = 0;

this will set the key code to zero .. So when the explorer checks the keyCode, it will be zero ... so the default function will not be executed ...

Try this ... just an offer

+1
source share

This works for me in IE 8. An important part of IE requires ev.returnValue to be set to false. NOTE: this only works if you focus on some element of the document ... that is, if you just load the page and press "ctrl-p", you will see a print dialog. But if you click somewhere on the page, try it; it should suppress the print dialog. A.

 document.onkeydown = function (e) { var ev = e||window.event; // Do what I want keys to do ... // Block browser short cuts if(ev.preventDefault) // non-IE browsers ev.preventDefault(); else // IE Only ev.returnValue = false; }; 
0
source share

All Articles