[Edit]
+
0
-
0

js capture right-click event

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<!-- Warning: using this approach be sure the right mouse button has number 3. --> <!doctype html> <html> <body> <button id="my-button">Right-click me</button> <script> var myButton = document.querySelector('#my-button'); var activeCase = null; // stores number of pressed mouse button myButton.addEventListener('mousedown', function(e) { activeCase = e.which; }); myButton.addEventListener('mouseup', function(e) { if (activeCase === 3) { // in 3 buttons mouse (left + scroll + right buttons) right one will have number 3 activeButton = null; console.log('Right button clicked!'); } }); myButton.addEventListener('blur', function(e) { activeButton = null; }); </script> </body> </html>