1

This simple piece of code works in Chromium but not in Firefox. Why, and what's the best way to disable page interaction while moving the mouse. I'm trying to implement drag and drop, and I want to disable interactions while dragging.

$('body').on('mousemove', function (event) {
  event.preventDefault();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Try to select this text.<br>
In Chromium, you can't, as expected.<br>
In Firefox, you can, as unexpected.

https://jsfiddle.net/zu0jpar2/

Paul
  • 6,061
  • 6
  • 39
  • 70

1 Answers1

0

You can use selectstart event.

$('body').on('selectstart', function (event) {
  event.preventDefault();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Try to select this text.<br>
In Chromium, you can't, as expected.<br>
In Firefox, you can, as unexpected.

Or CSS user-select property:

body {
   user-select: none;
}
Try to select this text.<br>
In Chromium, you can't, as expected.<br>
In Firefox, you can, as unexpected.
m51
  • 1,950
  • 16
  • 25
  • This works for this specific example, but it's specific to text selection, right? I want to block move events in general. – Paul Nov 01 '20 at 15:29