Disable mouse right click in HTML using JavaScript

28 May 2015 Kamal Pratap
0 Comments 2981 Views

Here we explain how to disable mouse right click on web page. Using this code you can easily disable right click without using other resources.

Java Script :

<script language="JavaScript" type="text/javascript">
        var message = "Function Disabled!";
        function clickIE4() {
            if (event.button == 2) {
                return false;
        function clickNS4(e) {
            if (document.layers || document.getElementById && !document.all) {
                if (e.which == 2 || e.which == 3) {
                    return false;
        if (document.layers) {
            document.onmousedown = clickNS4;
        else if (document.all && !document.getElementById) {
            document.onmousedown = clickIE4;
        document.oncontextmenu = new Function("alert(message);return false")

Put the above code in the head section on your web page to disable the right click permanently.

Kamal Pratap

I have 6+ years experience in .Net technologies like Asp.Net, C#, WCF, Web Services, SQL Server, Ajax, LinQ. Currently I am working in Netcarrots Loyalty Services as a Software Developer.


No coments found to display!

Leave a Comment