在IE 8中禁用Ctrl键

时间:2016-02-11 10:23:12

标签: javascript internet-explorer disabled-control

我想在IE浏览器中禁用ctrl键。我曾尝试使用javascript的一些解决方案,但没有任何工作可以有人请帮我找出解决方案



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


document.onkeydown = function(e) {
         if (e.altKey && (e.keyCode === 36)) {//Alt+home blocked.
            return false;
        }
        if (e.altKey && (e.keyCode === 70)) {//Alt+f blocked.
            return false;
        }
    };


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 个答案:

答案 0 :(得分:0)



function Disable_Control_C() {
var keystroke = String.fromCharCode(event.keyCode).toLowerCase();

if (event.ctrlKey && (keystroke == 'c' || keystroke == 'v' || keystroke == 'p' || keystroke == 's' || keystroke == 'u')) {
alert("this function is disabled");
event.returnValue = false; // disable Ctrl+C
}
}

<body onkeydown="javascript:Disable_Control_C()">
&#13;
&#13;
&#13;

这就是我在IE中运行它...