How to Simulate Command+Click in JavaScript

--

For some reason you are simulating links with JavaScript like:

But you want to open the link in another tab as you do when clicking on the link with Command pressed.

There you go:

metaKey is Command key on macOS and Windows key on Windows.

You might want to check its support across browsers.

Bonus

There is also another property ctrlKey with the same behaviour but for Ctrl key on Windows and Control on macOS.

--

--