如何使用JavaScript禁用功能键? [英] How to Disable Function keys using Javascript?

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

问题描述

我有一个网页,我需要禁用功能键主要是F12(Developertools)。
我展示了一些敏感数据的页面,以便在任何情况下,我不能让用户看到的HTML,并采取隐藏字段。
我查了一些JavaScript这是工作的几乎所有的按键,除了像F1,F12等。

I'm having a page where i need to disable the Function keys mainly F12(Developertools). I'm showing some sensitive data in the page so at any case i cannot make the users see the html and take the hidden fields. I checked some javascript which is working for almost all the keys except the Function keys like f1, f12 etc.

反正是有,我可以在浏览器中禁用这些按钮?

Is there anyway that i can disable these buttons in the browser?

document.onkeyup = KeyCheck;
function KeyCheck() {
    var KeyID = event.keyCode;
    alert(KeyID);
    switch (KeyID) {
        case 123:  //F12 KEY CODE         
            alert('hello');
            return false;
            break;            
    }

}

这是code这即时通讯使用覆盖的关键。当我搜索,F12键的键code是使用相同的code来覆盖它123和IM。但不幸的是它甚至没有击中CASE,消息框未出现在pressing F12,F1等按键。

This is the code which im using for overriding the key. When I searched, the keycode of F12 key is 123 and im using the same code for overriding it. But unfortunately its not even hitting the "CASE" and the message box is not appearing when pressing F12, F1 etc buttons.

请帮我在这。

推荐答案

有是从你的JavaScript的数据,当你发送它篡改prevent用户没有可靠的方法。总是使用服务器端的检查,以验证返回的数据。

There is no reliable way to prevent users from tampering with your javascript data, when you've sent it. Always use server-side checks to verify the returned data.

人们仍然可以使用浏览器的菜单,使开发者控制台。或者通过<大骨节病>右键单击 - >检查元素,或者使用快捷键打开控制台的不同部分,然后按Tab键在控制台另一页,或使用我的热键之一已经没有提到。结果
或者,他们可以简单地禁用javascript。 (或编辑的javascript禁用块)

People can still use the browser's menu to enable the dev console. Or through right-click --> "Inspect Element", or by using hotkeys to open different sections of the console, then tabbing to another page in the console, or by using one of the hotkeys I've failed to mention.
Or, they can simply disable javascript. (Or edit the javascript to disable the block)

现在,你可以稍微更彻底的禁用任何按钮的功能,加入了:结果
事件。preventDefault()在你的事件监听器,不过,这是不可靠的。

Now, you can be a little more thorough in disabling whatever button's functionality, by adding a:
event.preventDefault() in your event listener, but still, it's unreliable.

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

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