Disable F12 Key in a Page Using jQuery

Introduction

In this post, we will see how we can disable F12 Key option using simple JQuery code. I hope you will like it.

Please see this article How to disable F12 Key in a page using JQuery  in my blog.

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.

  1. <script src="http://sibeeshpassion.com/content/scripts/jquery-1.11.1.min.js"></script>  

Now we need to add the needful scripts.

  1. <script>  
  2. document.onkeypress = function (event) {  
  3. event = (event || window.event);  
  4. if (event.keyCode == 123) {  
  5. return false;  
  6. }  
  7. }  
  8. document.onmousedown = function (event) {  
  9. event = (event || window.event);  
  10. if (event.keyCode == 123) {  
  11. return false;  
  12. }  
  13. }  
  14. document.onkeydown = function (event) {  
  15. event = (event || window.event);  
  16. if (event.keyCode == 123) {  
  17. return false;  
  18. }  
  19. }  
  20. </script>  

Here what we did is, whenever user press F12 , we are restricting that. We are applying this restriction to the entire document. And we use onkeypress ,onmousedown ,onkeydown event to do this requirement.

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


Similar Articles