Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Does HTML support middle click?
- VoidInstructions
-
Scratcher
76 posts
Does HTML support middle click?
Can you code HTML in such a way that it overrides the default functionality of the middle clicks?
- Sheep_maker
-
Scratcher
1000+ posts
Does HTML support middle click?
You'd need JavaScript:
<script> // Whenever the user starts pressing any mouse button document.addEventListener('mousedown', e => { // Check if the click is the middle button if (e.which === 2) { // Do something when the user does middle click alert('Middle click!') // Prevent default middle click behaviour of the middle click e.preventDefault() } }) </script>
- Maximouse
-
Scratcher
1000+ posts
Does HTML support middle click?
You'd need JavaScript:MDN say that event.which is not standard and should not be used on production sites (but every browser supports it).<script> // Whenever the user starts pressing any mouse button document.addEventListener('mousedown', e => { // Check if the click is the middle button if (e.which === 2) { // Do something when the user does middle click alert('Middle click!') // Prevent default middle click behaviour of the middle click e.preventDefault() } }) </script>
- A-E-
-
Scratcher
100+ posts
Does HTML support middle click?
Updated to standardize:You'd need JavaScript:MDN say that event.which is not standard and should not be used on production sites (but every browser supports it).<!-- snip -->
<script> // Whenever the user starts pressing any mouse button document.addEventListener('mousedown', e => { // Check if the click is the middle button if (e.button === 1) { // Do something when the user does middle click alert('Middle click!') // Prevent default middle click behaviour of the middle click e.preventDefault() } }) </script>
- Discussion Forums
- » Advanced Topics
-
» Does HTML support middle click?