Disable right click on web page using JavaScript.

Mohammed Imtiyaz Dec 6, 2014

In this article, we will explain you how to disable right click on web page using JavaScript.

Just copy the JavaScript code after title tag under head tag.

TEST: Right click on the page to test the code. (Right click is disabled)
<!DOCTYPE html>
<html>
<head>
    <script language="javascript" type="text/javascript">
        var isNS = (navigator.appName == "Netscape") ? 1 : 0;

        if (navigator.appName == "Netscape") {
            document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP);
        }

        function mischandler() {
            return false;
        }

        function mousehandler(e) {
            var myevent = (isNS) ? e : event;
            var eventbutton = (isNS) ? myevent.which : myevent.button;
            if ((eventbutton == 2) || (eventbutton == 3)) return false;
        }

        document.oncontextmenu = mischandler;
        document.onmousedown = mousehandler;
        document.onmouseup = mousehandler;
    </script>
</head>

<body>
    Body contents here..
</body>
</html>