0

How can I change the default behaviour of the left mose button so that it acquires the default property of the middle button, but only for a specific instance?

Eg.

<a id="special" href="https://www.google.com">CLICK ME</a>

<a href="https://www.bing.com">CLICK ME</a>

This is not real JS just pseudo code:

$('#special') function tmpSwap {
    if(event.button == 1)
        Return event as button 2 (aka button(1) is now button(2))
    }
}

Button 1 - left Button 2 - middle

So any time a hyperlink with the specific named anchor is left clicked the script runs and the behaviour that follows equates to behaviour as if the link was middle clicked.

u24b8
  • 15
  • 6

1 Answers1

1

The only real options you have are:

  1. A normal link, and the user is in control by using left-click, middle-click, shift-click, shift-ctrl-click, etc.

  2. A link with target="_blank", which will open a new window or tab depending on the user's browser configuration.

  3. A link with target="some_name", which will open in a new window or tab (depending on the user's browser configuration) or in an existing window/tab if this is the second time they've done it.

  4. Use a click handler and, within the handler, do a window.open with a target window name (but this largely just duplicates options 2 and 3 above).

You can't do much more than that. Nor, arguably, should you.


Side note: There is no universal action for middle-click, cross-OS, cross-browser.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875