disable image dragging and right click code example

Example: disable image dragging and right click

<!--Place the javascript code at the button of the page -->
     
     <script>
          $('img').bind('contextmenu', function(e) {
            return false;
        }); 
        
        $('#nearestStaticContainer').on('contextmenu', 'img', function(e){ 
          return false; 
        });
        
        $('body').on('contextmenu', 'img', function(e){     return false; });
        
        $(function(){
             $('body').on('contextmenu', 'img', function(e){ 
                 return false; 
             });
         });
        
         const images = document.getElementsByTagName('img');
        for (let i = 0; i < images.length; i++) {
            images[i].addEventListener('contextmenu', event => event.preventDefault());
        }
        
        $('img').bind('contextmenu', function(e){
            alert("Action is prohibited");return false;
        });
        </script>

Tags:

Css Example