0

I suppose JavaScript would be my best option for this because it's a client side.

There are two ways you can click a link which I will be focusing on - you can click the link OR right click it and select open in new tab.

How would I detect whether the user has clicked the link or opened it in a new tab?

The Codesee
  • 3,714
  • 5
  • 38
  • 78
  • "you can click the link OR right click it and select open in new tab." Or Ctrl+Click, or Middle-Click, or Ctrl+Enter (and that's just about opening a new _tab_ without accounting for opening a new _window_ with e.g. Shift+Click or Shift+Enter). Actually, what matters here is not how to detect this, but _why_ you need this. – Marat Tanalin Jul 09 '16 at 18:14

1 Answers1

1

You can distinguish click events below.

$('#element').mousedown(function(event) {
switch (event.which) {
    case 1:
        alert('Left Mouse button pressed.');
        break;
    case 2:
        alert('Middle Mouse button pressed.');
        break;
    case 3:
        alert('Right Mouse button pressed.');
        break;
    default:
        alert('You have a strange Mouse!');
}
});
ima0123
  • 85
  • 1
  • 10