Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to disable right-click option using the jQuery ?

  • Last Updated : 10 Dec, 2020

The bind() method in jQuery is used to attach one or more event handlers for selected element and this method specifies a function to run when an event occurs.

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

$(selector).bind(event, data, function);

Parameters: This method accepts three parameters as mentioned above and described below:

  • event: It is an event type which is passed to the selected elements.
  • data: It is the data which can be shown over the selected elements.
  • function: It is the function which is performed by the selected elements.

Return Value: It returns all the modification made on the selected element.



In this article, we will see how to disable the right-click option using the jQuery bind() method.

HTML




<!DOCTYPE html>
<html>
  
<head>
  
    <!-- Adding jQuery scripts required to run jQuery -->
    <script src=
    </script>
  
    <!-- This script will prevent 
        right click -->
    <script>
        $(document).ready(function () {
            $(document).bind("contextmenu", function (e) {
                return false;
            });
        });
    </script>
  
    <!-- Adding style -->
    <style>
        h1 {
            color: green;
        }
        p {
            color: crimson;
        }
    </style>
</head>
  
<!-- Body of the page -->
<body>
    <center>
        <h1>GeeksForGeeks</h1>
  
        <p>
            GeeksforGeeks is a Computer Science
            portal for geeks. It contains well
            written, well thought and well
            explained computer science and
            programming articles, quizzes etc.
        </p>
    </center>
</body>
  
</html>

Output:

You can see that you can’t open the right-click option window by right-clicking on the screen.




My Personal Notes arrow_drop_up
Recommended Articles
Page :