How to disable right click using jQuery?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Hello Dev’s, Today in this article, i will show you how a example of disable right click by using jquery on div. Now If You are looking for a short and also a simple way to disable right click for any html element then I hope here you will find the best solution to disable right click on any page.

Now there are some reasons why we need disable the right click of mouse button in our website.

It may be we don’t want to show our own menu html page source code on right click disable on a by using the jQuery bind() method.

Example



<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>

<h3>Right click is disabled on this page.</h3>

<script>
$(document).ready(function(){
     $(document).bind("contextmenu",function(e){
     	 alert('right click disabled');
        return false;
    });
});
</script>
</body>
</html>

Read Also : How to Get difference between two dates in days using carbon in laravel

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →