Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can not disable Ctrl+O by JavaScript in IE 11

I'm trying to disable Ctrl+o key combination in IE, the following code works fine in all IE versions except IE 11 unless I do an alert as you see in code below:

document.onkeydown = function(event) {
    var x = event.keyCode;
    console.log(event.keyCode);
    console.log(event.ctrlKey);
    if ((x == 79) && (event.ctrlKey)) {
        if(navigator.userAgent.match(/rv:11.0/i)){
            alert('Disabled');
        }
        event.cancelBubble = true;
        event.returnValue = false;
        event.keyCode = 0;
        event.stopPropagation();
        event.preventDefault();

        return false;
    }
};

I was wondering if anyone else is experiencing the same issue and they have solved it. :-) Thanks. Alex

like image 554
Alex Avatar asked Feb 28 '14 00:02

Alex


1 Answers

I have no good solution unfortunately, but have created a case with Microsoft, and made a jfiddle that demonstrates the issue.

The only way we have found around this is the use of the:

<meta http-equiv="X-UA-Compatible" content="IE=7">

header, but there's no telling when support for that will go away - not to mention the obvious side-effects of running in IE7 mode.

Some additional notes:

  • Although the interception works natively on IE8 and IE9, only the IE=7 UA mode works
  • A page reload is required for the header to take effect, whether it is in the page or returned in the server response i.e. you cannot selectively jump in an out of IE7 mode in a single page app
  • Here is a link to the standards that IE11 was built against: http://www.w3.org/TR/DOM-Level-3-Events/#KeyboardEvent-supplemental-interface

Fiddle:

http://jsfiddle.net/bw5sLd15/1/

// The kitchen sink
function killKey( event ) {
    event.cancelBubble = true;
    event.bubbles = false;
    event.returnValue = false;
    event.stopPropagation();
    event.stopImmediatePropagation();
    event.preventDefault();
    return false;
}
like image 64
Max Mammel Avatar answered Oct 13 '22 02:10

Max Mammel