How to disable default Help function of browsers

后端 未结 1 1803
栀梦
栀梦 2021-01-06 04:18

I want to disable or override the default help function of browsers.

I tried to look at few examples online but they are not working for me. (The following code is

相关标签:
1条回答
  • 2021-01-06 04:49

    I've found here this code that was clamied to work in each version of IE and FF

    <script type="text/javascript">
    
    function avoidInvalidKeyStorkes(evtArg) {
        var evt = (document.all ? window.event : evtArg);
        var isIE = (document.all ? true : false);
        var KEYCODE = (document.all ? window.event.keyCode : evtArg.which);
    
        var element = (document.all ? window.event.srcElement : evtArg.target);
        var msg = "We have disabled this key: " + KEYCODE;
    
        if (KEYCODE == "112") {
            if (isIE) {
                document.onhelp = function() {
                    return (false);
                };
                window.onhelp = function() {
                    return (false);
                };
            }
            evt.returnValue = false;
            evt.keyCode = 0;
            window.status = msg;
            evt.preventDefault();
            evt.stopPropagation();
            alert(msg);
        }
    
        window.status = "Done";    
    }    
    
    if (window.document.addEventListener) {
        window.document.addEventListener("keydown", avoidInvalidKeyStorkes, false);
    } else {
        window.document.attachEvent("onkeydown", avoidInvalidKeyStorkes);
        document.captureEvents(Event.KEYDOWN);
    }
    
    </script>
    

    Working JSFiddle. Note that you have to test it after clicking the result tab.

    0 讨论(0)
提交回复
热议问题