How to disable mouse scroll button?

Asked

Viewed 3,677 times

9

I would like to know how to disable the central button of mouse who has the scroll?

I don’t want to take the scroll just the button of scroll of mouse that features arrow to left up and down when you click on it, I want to disable it.

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 the same way. Try this code on Jsfiddle.

4

You can prevent the click with the scroll button, 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>Clique com o botão do scroll</div>

With pure javascript, make:

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>

  • 1

    Thanks for the help I help a lot, gave straight here, thanks guys.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.