Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  11] [ 1]  / answers: 1 / hits: 22941  / 12 Years ago, mon, july 9, 2012, 12:00:00

I'm trying to find a way of disabling the default action of the mouse wheel button which is to open the link in a new tab.



Is that possible?


More From » jquery

 Answers
1

Bind a generic click event handler that specifically checks for middle clicks. Within that event handler, call e.preventDefault():



$(#foo).on('click', function(e) { 
if( e.which == 2 ) {
e.preventDefault();
}
});


Note that not all browsers support preventing this default action. For me, it only works in Chrome. Firefox, Opera and IE9 all do not raise the click event with middle mouse click. They do raise mouseup and mousedown.


[#84386] Friday, July 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrellhunterm

Total Points: 82
Total Questions: 109
Total Answers: 98

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
;