Answers for "how to disable dragging of images cs"

3

how to disable image dragging in html

use ondragstart="return false" for dragging and onselectstart="return false" for selecting
Posted by: Guest on August-01-2020
0

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>
Posted by: Guest on November-15-2020

Code answers related to "how to disable dragging of images cs"

Browse Popular Code Answers by Language