Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling middle click scrolling with javascript

Background: I am creating a table reminiscent of whenisgood.net, in that it has click-n-drag toggling for table elements. I want to call different types of toggling code when the left, middle, and right mouse buttons activate a mousedown event.

By using JQuery, I'm off to a good start.

$(".togglable").bind("contextmenu", function() {return false;});
$(".togglable").bind("mousedown", function(e){
  e.preventDefault();
  toggle(this, e);
});

In the toggle() function I can use e.which to determine what button was clicked.

The punchline: I used e.preventDefault() hoping that it would stop the middle click default behavior of scrolling. It didn't. What can I do to stop the scroll action from activating?

See also "Triggering onclick event using middle click"

like image 930
Dan Burton Avatar asked Dec 18 '09 21:12

Dan Burton


People also ask

How do I stop Div scrolling?

To hide the scrollbar and disable scrolling, we can use the CSS overflow property. This property determines what to do with content that extends beyond the boundaries of its container. To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element.

How do I disable my Mouse roller?

Open the Registry Editor by clicking Start and typing regedit and hit enter. Navigate to HKEY_CURRENT_USER\Control Panel\Desktop and set WheelScrollChars and WheelScrollLines to 0. A reboot is necessary for this to take affect. This will disable scrolling, not the button itself.


2 Answers

Middle-click can be disabled with Javascript, but only in IE, WebKit, and Konquerer. Firefox requires a config file edit. It's 2017 and firefox 50 supports this.

like image 79
Josh Stodola Avatar answered Oct 04 '22 12:10

Josh Stodola


This is an old question...but if I'm understanding it properly, you want to disable scrolling via the middle mouse button click.

Nowadays, you can do this with a single line of vanilla JS:

document.body.onmousedown = function(e) { if (e.button === 1) return false; }
like image 27
rnevius Avatar answered Oct 04 '22 14:10

rnevius