0

I am trying to stop or prevent IE11 default behavior of "Ctrl+F4" key. I have tried

        function killKey( event ) {
    event.cancelBubble = true;
    event.bubbles = false;
    event.returnValue = false;
    event.stopPropagation();
    event.stopImmediatePropagation();
    event.preventDefault();
    return false;
    }

function avoidInvalidKeyStorkes(evtArg) {
if(evtArg.which == 115){
//alert("test");
killKey(evtArg);
}
}

if (window.document.addEventListener) {
window.document.addEventListener("keydown", avoidInvalidKeyStorkes, false);
} else {
window.document.attachEvent("onkeydown", avoidInvalidKeyStorkes);
document.captureEvents(Event.KEYDOWN);
}

But still the window got closed when i press Ctrl+F4.

but if i put alert() on top of code, it will work. But without alert() default event not prevented. Can any one suggest me the solution.

  • He explain here why you can't https://stackoverflow.com/questions/19938576/disable-altf4-yes-i-know-it-isnt-recommended/22263935 – mehdim2 Mar 03 '21 at 12:56
  • Or maybe try this https://stackoverflow.com/questions/1565304/jquery-prevent-window-closing – mehdim2 Mar 03 '21 at 12:57

0 Answers0