Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  5] [ 1]  / answers: 1 / hits: 34712  / 14 Years ago, wed, october 6, 2010, 12:00:00

Firefox has this annoying behavior that it let's the user drag and drop any image element by default. How can I cleanly disable this default behavior with jQuery?


More From » jquery

 Answers
101

The following will do it in Firefox 3 and later:



$(document).on(dragstart, function() {
return false;
});


If you would prefer not to disable all drags (e.g. you may wish to still allow users to drag links to their link toolbar), you could make sure only <img> element drags are prevented:



$(document).on(dragstart, function(e) {
if (e.target.nodeName.toUpperCase() == IMG) {
return false;
}
});


Bear in mind that this will allow images within links to be dragged.


[#95402] Saturday, October 2, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
paolam

Total Points: 437
Total Questions: 107
Total Answers: 106

Location: Aland Islands
Member since Wed, Nov 17, 2021
3 Years ago
;