Wednesday 25 July 2012

Disable Ctrl Key, Right click and F12

Hi ,
Just copy and paste this code and save your file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Disable Ctrl Key, Right click and F12 </title>
<script language="JavaScript">

//////////F12 disable code////////////////////////
    document.onkeypress = function (event) {
        event = (event || window.event);
        if (event.keyCode == 123) {
           //alert('No F-12');
            return false;
        }
    }
    document.onmousedown = function (event) {
        event = (event || window.event);
        if (event.keyCode == 123) {
            //alert('No F-keys');
            return false;
        }
    }
document.onkeydown = function (event) {
        event = (event || window.event);
        if (event.keyCode == 123) {
            //alert('No F-keys');
            return false;
        }
    }
/////////////////////end///////////////////////


//Disable right click script
//visit http://www.rainbow.arch.scriptmania.com/scripts/
var message="Sorry, right-click has been disabled";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
//
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j' , 'w');
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode;     //IE
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which;     //firefox
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
//if ctrl is pressed check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i<forbiddenKeys.length; i++)
{
//case-insensitive comparation
if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
{
alert('Key combination CTRL + '+String.fromCharCode(key) +' has been disabled.');
return false;
}
}
}
return true;
}
</script>
</head>
<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);">
Press ctrl and you can check various key is disable with CTRL. like  — 'a', 'n', 'c', 'x', 'v', 'j' , 'w' Just add key in above the array and disable key as you want.
</body>
</html>

38 comments:

  1. Replies
    1. at html writer were u always write html !!
      if dont understand type on gooogle !!!

      Delete
  2. IE & firefox only :( ..

    ReplyDelete
    Replies
    1. Great solution...working in all browser

      Delete
  3. can u plz tell where to add this in blogger

    ReplyDelete
  4. hmm http://edelajans.com/

    ReplyDelete
  5. You are amazing, cool, and everything.........words are not enough to say!!!!!

    ReplyDelete
  6. You could definitely see your enthusiasm in the article you write. The world hopes for even more passionate writers like you who aren’t afraid to say how they believe. At all times follow your heart.
    website design

    ReplyDelete
  7. it's not working in chrome

    ReplyDelete
  8. Very usefull thanks!!

    ReplyDelete
  9. Thanks, But its not working in chrome. I urgent need to disable it on all browser.

    ReplyDelete
  10. its good but how to disable developer tools

    ReplyDelete
  11. it works but if you try to press that key ( ctrl + u ) more than one time then it will not working

    ReplyDelete
    Replies
    1. on the line
      forbiddenKeys var = new Array ('a', 'n', 'c', 'x', 'v', 'j', 'w');
      You must add the letter 'u' to mention that the variable 'u' will work with the CTRL key, so when you hit ctrl + u will display a Feedback.
      should look like this:
      forbiddenKeys var = new Array ('a', 'n', 'c', 'x', 'v', 'j', 'w', 'u');

      Hope this helps.

      Delete
  12. Very good, tested and approved in recent versions of Chrome, Fire Fox, Opera and Safari.
    Only gave error in IE 11, the functions do not work.
    Anyone know how to fix?
    Thanks and a big hug.

    ReplyDelete
  13. very good and useful information shared. Thanks for sharing this.

    ReplyDelete
  14. Its not working in IE9... Can any one please tell me how to solve this??

    ReplyDelete
  15. Makes no sense. Anyone with a knowledge of F12 tools will bypass everything.

    ReplyDelete
    Replies
    1. what if we disable right click and F12 both ? :p

      Delete
    2. Hi... How to disable it on address. Because F12 key is working on addressbar.

      Delete
  16. Thanks for sharing the important points of view with us. It is really very nice blog which describes how to icici payment gateway plugin

    ReplyDelete
  17. Thanks...It's Working..:)

    ReplyDelete
  18. Great Article i have learned so many things from your article

    Please check this and tell me more about it:
    http://seowebsitedesigning.com/disable-mouse-right-click-using-jquery/

    ReplyDelete
  19. Thanks for sharing the important points of view with us.

    ReplyDelete
  20. Sir i have one question how we create full screen browser while writing online exams please reply me as early as posiable..........

    ReplyDelete

Note: only a member of this blog may post a comment.