Discuss Scratch

voidedminh
Scratcher
69 posts

Does HTML support middle click?

Can you code HTML in such a way that it overrides the default functionality of the middle clicks?

Generation 379: The first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment. (I did not start this.)
forever
delete kumquats :: custom
end
NOW I can take care of these kumquats.
What do you mean evil mangoes-
Sadly, my signature has been eaten by an evil mango.
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>

- Sheep_maker This is a kumquat-free signature. :P
This, my signature, appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
Maximouse
Scratcher
1000+ posts

Does HTML support middle click?

Sheep_maker wrote:

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>
MDN say that event.which is not standard and should not be used on production sites (but every browser supports it).

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
A-E-
Scratcher
100+ posts

Does HTML support middle click?

Maximouse wrote:

Sheep_maker wrote:

You'd need JavaScript:
<!-- snip -->
MDN say that event.which is not standard and should not be used on production sites (but every browser supports it).
Updated to standardize:
<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>

Powered by DjangoBB

Standard | Mobile