Tuesday, September 25, 2012

Disable Right Click In a Web Page

We can disable right click on apage using the following code

  <script type="text/javascript">
        document.onmousedown = clickfn;

        function clickfn(e) {
            var button;
            if (navigator.appName == "Microsoft Internet Explorer") {
                button = event.button;
              
            }
            else {
                button = e.buttons;
            }

            if (button == 2) {
                alert("Right Click Disabled");

                if (navigator.appName == "Microsoft Internet Explorer") {
                    event.returnValue = false;
                }               
                return false;
            }
        }
    </script>



navigator.appName == "Microsoft Internet Explorer"  this is used because in ie 7 "e" is not supported so we used event in common for all ie versions...

7 comments:

  1. nice share gan, sekedar tambahan untuk chrome perlu ngehandle even document.oncontextmenu juga, klo ndak gitu menu klik kanan nya masih keluar..

    ReplyDelete
    Replies
    1. bagaimana cara handle document.oncontextmenu nya..?
      boleh minta contoh codes nya..?

      Delete
  2. how to disable second dialog box i.e "prevent this page from creating additional dialogs"??

    ReplyDelete
  3. please tell as soon as possible??it is urgent..

    ReplyDelete
  4. thank you very much.. just copy paste working fine

    ReplyDelete
  5. Hello Bro., Sorry to say that I can right click on your web page at scroll bar and can hack source code...

    ReplyDelete
  6. By pressing F12 key any one can go to source code.

    ReplyDelete