如何禁用浏览器的默认帮助功能 [英] How to disable default Help function of browsers

查看:177
本文介绍了如何禁用浏览器的默认帮助功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想停用或覆写浏览器的预设帮助功能。



我试图在网上查看几个例子,但他们不适合我。
(以下代码在ff和chrome上工作,但不在opera和ie上工作)

 < html& 
< title>
< / title>
< body>
< script src =jquery-1.7.1.min.jstext =type =text / javascript>< / script>
< script language =javascripttype =text / javascript>
document.onkeydown = function(event)
{
if(window.event&& window.event.keyCode == 112)
{
event。 stopPropagation();
event.preventDefault();
event.keyCode = 0;
return false;
//document.onhelp = new Function(return false;);
//window.onhelp = new Function(return false;);
// helpFunction();

}
else if(event.which == 112)
{
helpFunction();
}
};
var false_function = new function(){return false;};
shortcut.add(f1,false_function);
var helpFunction = function(){
alert('help');
}
< / script>
< h2>测试< / h2>
< / body>

解决方案>

我找到了这里这个代码,它被列为在每个版本的工作IE和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 =我们已禁用此键:+ 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>

工作 JSFiddle 。请注意,您必须在点击结果标签后对其进行测试。


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 working on ff and chrome but not on opera & ie)

<html>
<title>
</title>
<body>
    <script src = "jquery-1.7.1.min.js" text="type="text/javascript""></script>
    <script language="javascript" type="text/javascript">           
            document.onkeydown = function(event)
            {
                if(window.event && window.event.keyCode == 112)
                {
                     event.stopPropagation();
                     event.preventDefault();
                     event.keyCode = 0;
                     return false;
                    //document.onhelp = new Function("return false;");
                    //window.onhelp = new Function("return false;");
                    //helpFunction();

                }
                else if(event.which == 112)
                {
                    helpFunction();
                }
            };
            var false_function = new function(){"return false";};
            shortcut.add("f1",false_function);
        var helpFunction = function() {
            alert('help');
        }
    </script>
    <h2>Test</h2>
</body>

解决方案

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.

这篇关于如何禁用浏览器的默认帮助功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆