voidedminh

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

Sheep_maker

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

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).

A-E-

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>