Breaking News
Loading...
,

Disable right click using jquery

Share on Google Plus

Disable right click using jquery




Disable right click

With the given code you can simpply disable the Right Click on hole of the page. However you can also disable right click on particular element.
$(document).bind('contextmenu'function (e) {
  e.preventDefault();
  alert('Right Click is not allowed');
});
CODE:

<!DOCTYPE html>
<html>
<head>
  <title>jQuery With Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $(document).bind('contextmenu', function (e) {
        e.preventDefault();
        alert('Right Click is not allowed');
      });

      /*$('.Container').bind('contextmenu',function(e){
      e.preventDefault();
      alert('Right Click is not allowed on div');
      });*/
    });
  </script>
</head>
<body>
  <div class="Container" style="border:1px solid Red; width:300px;">
    <p>Please right Click here for test this example</p>
    <input type="text" /><br>
    <input type="checkbox" />
  </div>
  <button id="btnClick">Click</button>
</body>
</html>

You Might Also Like

0 comments

About me


Like us on Facebook