How to prevent Right Click option using jquery

前端 未结 12 2113
心在旅途
心在旅途 2020-12-02 11:23

Is it possible to prevent RIGHT CLICK option for IMAGES which we use in web page.

相关标签:
12条回答
  • 2020-12-02 11:51
    $(document).ready(function() {
        $("img").on("contextmenu",function(){
           return false;
        }); 
    }); 
    

    Working example: http://jsfiddle.net/vak9exyk/

    0 讨论(0)
  • 2020-12-02 11:51

    I think this should help. Trick is to bind the contextmenu event.

    <script type="text/javascript" language="javascript">
            $(function() {
                $(this).bind("contextmenu", function(e) {
                    e.preventDefault();
                });
            }); 
    </script>
    
    0 讨论(0)
  • 2020-12-02 11:54
    $(document).mousedown(function(e) {
        if( e.button == 2 ) {
             e.preventDefault();
            return false;
        } 
    });
    
    0 讨论(0)
  • 2020-12-02 12:00

    Method 1:

    <script type="text/javascript" language="javascript">
            $(document).ready(function(){
    
            $(document).bind("contextmenu",function(e){
    
                return false;
    
                });
    
        });
    
    </script>
    

    Method 2:

    <script type="text/javascript" language="javascript">
            $(document).ready(function(){
    
            $(document).bind("contextmenu",function(e){
    
                e.preventDefault();
    
                });
    
        });
    
    </script>
    
    0 讨论(0)
  • 2020-12-02 12:01

    Here i have found some useful link, with live working example.

    I have tried its working fine.

    How to prevent Right Click option using jquery

    $(document).bind("contextmenu", function (e) {
            e.preventDefault();
            alert("Right Click is Disabled");
        });
    
    0 讨论(0)
  • 2020-12-02 12:02
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script>
     $(document).ready(function(){
      $(document).bind("contextmenu",function(e){
      return false;
      });
    });
    </script>
    </head>
    <body>
    
    <p>Right click is disabled on this page.</p>
    
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题