In this article we will learn about some of the frequently asked HTML programming questions in technical like “how to disable image dragging in html” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on html was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in HTML. Below are some solution about “how to disable image dragging in html” Code Answer’s.
html disable drag image
xxxxxxxxxx
1
<img src="" alt="" draggable="false">
how to disable image dragging in html
xxxxxxxxxx
1
use ondragstart="return false" for dragging and onselectstart="return false" for selecting
disable image dragging and right click
xxxxxxxxxx
1
<!--Place the javascript code at the button of the page -->
2
3
<script>
4
$('img').bind('contextmenu', function(e) {
5
return false;
6
});
7
8
$('#nearestStaticContainer').on('contextmenu', 'img', function(e){
9
return false;
10
});
11
12
$('body').on('contextmenu', 'img', function(e){ return false; });
13
14
$(function(){
15
$('body').on('contextmenu', 'img', function(e){
16
return false;
17
});
18
});
19
20
const images = document.getElementsByTagName('img');
21
for (let i = 0; i < images.length; i++) {
22
images[i].addEventListener('contextmenu', event => event.preventDefault());
23
}
24
25
$('img').bind('contextmenu', function(e){
26
alert("Action is prohibited");return false;
27
});
28
</script>