0

How to disable mouse middle click scrolling on Firefox and IE 7 using jquery:

Below function is not working on these browsers:

$('body').mousedown(function(e)
{
  if((e.button === 1) || (e.button === 2)) 
  {
  e.preventDefault();     
  e.preventScrolling();       
  return false;   
   }
 });
K.K_7
  • 1
  • 1
  • did you find any errors in console ? – dreamweiver Sep 12 '13 at 06:17
  • Yes I noticed the error for e.preventScrolling(); function as it is not a function so I removed it and it is still working fine on chrome, and above versions of IE7 but not working on FF and IE 7. – K.K_7 Sep 12 '13 at 06:46
  • I hope this could help in that case ,http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie – dreamweiver Sep 12 '13 at 06:51
  • you can give this also a try,http://stackoverflow.com/questions/1526161/gwt-disable-middle-mouse-button-scroll-for-firefox – dreamweiver Sep 12 '13 at 07:24

1 Answers1

0

( Answer copied from: Disabling middle click scrolling with javascript )

$("body").wrap(
  "<a href='javascript:void(0);'
  onclick='return false;'></a>"
);

By wrapping it in a link (via jquery wrap), browsers think it's a link and don't scroll on middle click, even if you drag your mouse around. With this setup, and my situation, there are a couple (minor) gotchas.

Firefox will open a new tab when you middle click, but only if you don't drag. Opera will open a new tab when you middle click, drag or not. That's why I used href='javascript:void(0);' instead of just href='#'--so that the client's browser wouldn't load a whole page, just a blank page with a strange url.

But this solution works like a charm on Chrome and Safari. It works well with IE8, except that now when I left-click-n-drag, it changes the pointer to a "can't do that" symbol, since it thinks I want to drag the link somewhere. Untested on older versions of IE.

Community
  • 1
  • 1
  • Thanks for replying but I just want to disable the autoscrolling feature of Firefox using jquery on middle click of mouse. – K.K_7 Sep 12 '13 at 06:53