How to disable right click on your website using javascript?

Today in this documentation we will learn how to disable right click on your website via javascript.

Follow the steps to disable right click on your website using javascript:

Step::1 Login to your cPanel and click on File Manager section

How to disable right click on your website using javascript

Step::2 Go inside public_html and edit the .html file for which you want to disable the right click option.

How to disable right click on your website using javascript

Here we taking sample.html for demonstration purpose.

Step::3 Right click over the file and choose the Edit option

How to disable right click on your website using javascript

Step::4 Enter the code given below under the body tag

<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></s
cript>
<script>
jQuery(document).ready(function(){
  jQuery(function() {
        jQuery(this).bind("contextmenu", function(event) {
            event.preventDefault();
            alert('Right click is disabled on this site!!')
        });
    });
});
</script>
 

</head>
<body>
Here is my code. Right click on me.
</body>
</html>

Step::5 Once you have added the code, click on Save changes button and close the editor.

How to disable right click on your website using javascript

Now test the file from a new tab in your web browser. You will find that right click has been been successfully disabled.

How to disable right click on your website using javascript

Thanks for Reading this article !!! We hope this was helpful to you all

Leave a Comment