js capture right-click event
HTML[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11 12 13<!doctype html> <html> <body> <button id="my-button">Right-click me</button> <script> var myButton = document.querySelector('#my-button'); myButton.addEventListener('auxclick', function() { console.log('auxclick event occurred.'); }); </script> </body> </html>
[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11<!doctype html> <html> <body> <button onauxclick="handleClick()">Double-click me</button> <script> function handleClick(){ console.log('auxclick event occurred.'); } </script> </body> </html>
[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11 12 13<!doctype html> <html> <body> <button id="my-button">Right-click me</button> <script> var myButton = document.querySelector('#my-button'); myButton.onauxclick = function() { console.log('auxclick event occurred.'); }; </script> </body> </html>
[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11 12 13<!doctype html> <html> <body> <button oncontextmenu="handleClick()">Right-click me</button> <script> function handleClick(){ console.log('oncontextmenu event occurred.'); } </script> </body> </html> <!-- Warning: oncontextmenu event is handled when context menu key on keyboard is pressed. -->
[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15<!doctype html> <html> <body> <button id="my-button">Right-click me</button> <script> var myButton = document.querySelector('#my-button'); myButton.addEventListener('contextmenu', function() { console.log('oncontextmenu event occurred.'); }); </script> </body> </html> <!-- Warning: oncontextmenu event is handled when context menu key on keyboard is pressed. -->
[Edit]
+
0
-
0
js capture right-click event
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15<!doctype html> <html> <body> <button id="my-button">Right-click me</button> <script> var myButton = document.querySelector('#my-button'); myButton.oncontextmenu = function() { console.log('contextmenu event occurred.'); }; </script> </body> </html> <!-- Warning: oncontextmenu event is handled when context menu key on keyboard is pressed. -->
[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>