Reputation: 1297
I was struggling with this and couldn't find an answer that works. I want to prevent someone from dragging an image on a page or make a right click on it (or future one that is displayed dynamically and save it.
I solved preventing right clicking through:
$(document).on('contextmenu', '.notRightClick', function(e){ return false; });
...but I can't disable draggable effect. I tried this : '.notRightClick'.draggable( 'disable' )
but doesn't work for future elements.
Update Note: The img I want to drag has the class 'notRightClick :
<img class="notRightClick" src="someimgurl" alt="">
If anyone knows, that would be helpful. Thanks
Upvotes: 0
Views: 137
Reputation: 253308
$(document).on('contextmenu drag dragstart', '.notRightClick', function(e){
return false;
});
Upvotes: 3
Reputation: 1297
One workaround is :
$(document).on('mousedown', '.notRightClick', function(e){ return false; });
This disables the behaviour for mousedown which also includes the drag feature
Upvotes: 0
Reputation: 2169
$('img').on('dragstart', function(event) { event.preventDefault(); });
Upvotes: 2