Wednesday, February 17, 2016

Disable right click using javascript

<script type="text/javascript">
        //Message to display whenever right click on website
        var message = "Sorry, right click has been disabled.";
        function click(e) {
            if (document.all) {
                 //Check the Mouse Button which is clicked.
                if (event.button == 2 || event.button == 3) {
                    //  alert(message);
                    return false;
                }
            }
            else {
                if (e.button == 2 || e.button == 3) {
                    e.preventDefault();
                    e.stopPropagation();
                    // alert(message);
                    return false;
                }
            }
        }
        if (document.all) {
            document.onmousedown = click;
        }
        else {
            document.onclick = click;
        }
        document.oncontextmenu = function () {
            return false;
        };
    </script>

No comments:

Post a Comment