Disable mouse right click using javascript


When we right click on the page and click on the view source option then page html source along with inline css will see. From the source code, they can figure out how you did things and where your graphics are stored, or just plain old copy your content coding. To prevent the user to know the source detail we disable right click on the page.

<script type="text/javascript">
        var message = "Right Click Disabled!";
        function DisableIE() {
            if (event.button == 2) { alert(message); return false; }
        }
        function DisableOther(e) {
            if (document.layers || document.getElementById && !document.all)
            { if (e.which == 2 || e.which == 3) { alert(message); return false; } }
        }
        if (document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = DisableOther; }
        else if (document.all && !document.getElementById) { document.onmousedown = DisableIE; }
        document.oncontextmenu = new Function("alert(message);return false")
</script>

Comments