Introduction
In this post, we will see how we can disable F12 Key option using simple JQuery code. I hope you will like it.
Background
As you know disabling F12 Key option or disable right click in our page, does not makes the content secured. Even though that is the reality, I am sharing this post to show how to disable the F12 Key in page.
Using the code
We are going to use JQuery for this requirement. So you need to load the JQuery reference first.
- <script src="http://sibeeshpassion.com/content/scripts/jquery-1.11.1.min.js"></script>
Now we need to add the needful scripts.
- <script>
- document.onkeypress = function (event) {
- event = (event || window.event);
- if (event.keyCode == 123) {
- return false;
- }
- }
- document.onmousedown = function (event) {
- event = (event || window.event);
- if (event.keyCode == 123) {
- return false;
- }
- }
- document.onkeydown = function (event) {
- event = (event || window.event);
- if (event.keyCode == 123) {
- return false;
- }
- }
- </script>
That is all. Everything is done and set. Now you need to see the output and demo right?
Demo
You can see a demo at Disable F12 Option Demo
You can see F12 option is not allowed in the demo page. You can always gives an alert also, if a user press F12.
Conclusion
I hope you liked my article. Now please share me your feedback. Thanks in advance.
Kindest Regards
Sibeesh Venu

Santhakumar MunuswamyPosted Jul 23, 2015, 3:15 PM
Thanks for sharing
Afzaal Ahmad ZeeshanPosted Jul 22, 2015, 7:51 AM
For you, Sam Hobbs. Java as C#, is a managed language (not a Microsoft's managed languag term). It does not compile into native code, such as machine code of binary commands. It instead compiles in bytecode (Java Bytecode: https://en.wikipedia.org/wiki/Java_bytecode). This is then executed by Java Virtual Machine when the application is running. JVM uses Just-in-time compilation and compiles this bytecode in the instructions that processor can execute. Just as C# disassembler, which converts the IL code to C# or VB.NET (same technology that is used by language converters for C# or VB.NET, they convert the IL to C# or VB.NET). Java disassemblers can also be used to convert that Java bytecode back to Java. Every high-level language that uses Just-in-time compilation, or a virtual machine can be converted back to source code. JavaScript on the other hand is not even a programming language, but a prototype based dynamic language. :-) I hope, you get my point about Java's conversion to and fro.
Afzaal Ahmad ZeeshanPosted Jul 22, 2015, 7:42 AM
I totally agree with Sam Hobbs, but I thought that was not an issue to be discussed here, whether to disable F12 or not. Many times discussions are whether to disable mouse right click or not. It helps nothing but just in making a worst UX for the users. Users want to right-click to download the image, it is not allowed, user uses a way around and may get other sensitive data in the cookies.
Sam HobbsPosted Jul 21, 2015, 12:56 PM
I assume a program could easily be written to get the HTML. So anyone that thinks they are making their web page code secure by disabling the F12 key is misinformed. We must assume that all client-side code can be viewed. Since Java (not JavaScript) is compiled it might be possible to make it difficult to see the corresponding source code, but that I am unfamiliar with.
Upendra Pratap ShahiPosted Jul 20, 2015, 5:05 AM
good. @sibi
Afzaal Ahmad ZeeshanPosted Jul 20, 2015, 4:37 AM
Sibeesh, I don't understand why are you using mouse events in this. Keyboard input and keyboard events have nothing to do with mouse inputs. Even their key codes are different and cannot be mapped. So, I suggest you remove the mouse event handler, it might confuse the readers and is not required at all.