I have a link.
If I click it the javascript for the onclick runs and we do not go to the href address. This is good.
If I right click it and choose open in new tab then we only go to the href address in a new tab and the onclick does not run. This is also good.
If I cntl and click (on windows - command and click on ios) then the onclick runs (presumably because a click has happened) and I go to the href address in a new tab. I don't want this. I just want the new tab to open.
<a href="http://www.google.co.uk" onclick="arguments[0].stopPropagation(); alert('Clicked')">Do some stuff</a>
Either - can I detect that my onclick also caused a new tab to open so I can choose not to run my code.
Or, is there another event I should be listening for.
What I want to happen on a ctrl and click is - new tab opens, my javascript code does not run (or I can choose what to do).
I need something that works across all (latest) browsers and operating systems if possible. I.e. I'd prefer not to have to check if cntr(17) was pressed. I would prefer to know the intent of the click was to open a new tab - I was hoping to see a dynamic target attribute on the event but I couldn't find it.
(PS - ignore the fact that arguments[0] might not exist in all browsers - this is just an example of my problem)
I don't think this is a duplicate of knowing if the control key was pressed (although it may well turn out to be the only way of checking). I am asking if there is a way of differentiating between targeting a link in a new window/tab and targeting a link in the same tab.