Search code examples
javascriptjquerykeyboard-shortcutsinternet-explorer-11zk

Shortcut key implementation for IE11


we are facing issue related to shortcut key implementation for IE11 .When we fire the Ctrl+R event it is working as refresh (F5 or Ctrl+R) of IE11. We have implemented shortcut key like below.

Anyone can help me how we can override the IE11 shortcut key like F5 or Ctrl+R.

We also try the below link .We are not able get how it is working.

Is there a way to capture/override Ctrl-R or F5 on IE using Javascript?

document.addEventListener("keydown", onKeyDown, false);
function onKeyDown(e) {
    e = e || window.event;
    var keyValue=0;
    var set = new Set([65,80,81,82,85,45,46]);
    var cont=false;
    //var isIE11 = navigator.userAgent.test(/Trident.*rv[ :]*11\./);
    if(isIE11){
        alert("ie11");
    }else{
        alert("not ie");    
    }
    if(e.ctrlKey){
        keyValue=17;
        if(set.has(e.keyCode)){
            cont=true;
        }
    }else if(e.shiftKey){
        keyValue=16;
        if((e.keyCode>=113 && e.keyCode<=118)&& e.keyCode!=115){
            cont=true;
        }
    }else if(e.altKey){
        keyValue=18;
        if(e.keyCode==76){
            cont=true;
        }
    }else if(e.keyCode>112&& e.keyCode<=123){
        cont=true;
    }
    if(cont){
        e.preventDefault();
        e.stopPropagation();
        e.returnValue = false;
        //tempAlert("close",5000);
        zAu.send(new zk.Event(zk.Widget.$('#content'), 'onCtrlKey', {key:e.keyCode,ctrlKey:keyValue},{toServer:true}));
    }
    return false;
}

Thanks

Sitansu


Solution

  • Sorry to tell you the bad news, but for security reasons this is simple not allowed. In IE it is actually possible to capture F5, Ctrl+R and other standard hotkeys like Ctrl+P, but IE will always perform the standard action afterwards or even simultaneously.

    So IMHO, to the question you've linked and to your own question the best answer is: https://stackoverflow.com/a/1400676/932282

    Even extensive libraries like Mousetrap or KeyboardJS won't be able to capture these type of shortcut keys reliably.