Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  97] [ 6]  / answers: 1 / hits: 135437  / 15 Years ago, wed, november 25, 2009, 12:00:00

I am using the onclick event of a hashed link to open a <div> as a pop up. But the middle click does not trigger the onclick event but only takes the href attribute value of the link and loads the URL in a new page. How can I use middle click to open the <div> as a popup?


More From » jquery

 Answers
32

EDIT


This answer has been deprecated and doesn't work on Chrome. You will most probably end up using the auxclick event, but please refer to other answers below.


/EDIT




beggs' answer is correct, but it sounds like you want to prevent the default action of the middle click. In which case, include the following




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

<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
<a id=foo href=http://example.com>middle click me</a>




preventDefault() will stop the default action of the event.


[#98228] Saturday, November 21, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billie

Total Points: 101
Total Questions: 114
Total Answers: 98

Location: Burundi
Member since Wed, Nov 25, 2020
4 Years ago
;