How to disable mouse scroll button?

9

I would like to know how to disable the scroll central button ?

I do not want to take the scroll just the scroll button of the mouse that has a right-hand side up and down when I click it, I want disable it.

    
asked by anonymous 17.04.2015 / 21:15

2 answers

8

You can try something like this:

$('body').mousedown(function(e) {
    if (e.button == 1) return false;
});

Note that older browsers may not work this way. Try this code on JSFiddle .

    
17.04.2015 / 21:43
4

You can prevent the scroll button from clicking, for example:

$('body').mousedown(function(e){
    /*button == 0 botão esquerdo do mouse
     *button == 1 botão do meio, ou botão de scroll
     *button == 2 botão direito do mouse
    */
    if(e.button==1){
      alert('Botão desabilitado');
      return false
    }
});
div{
  width:100%;
  height:300px;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div>Cliquecomobotãodoscroll</div>

Withpurejavascript,do:

document.body.onmousedown = function(e){
    if(e.button == 1) {
      alert('Botão desabilitado');
      return false;
    }
}
div{
    width:100%;
    height:600px;
}
<div>Clique com o botão de scroll</div>
    
17.04.2015 / 21:47