0

I'm using window.history and intercepting link clicks:

document.querySelector('a[data-history]').addEventListener('click', function (e) {
  e.preventDefault()
  // window.history stuff
})

The problem now is that if I want to open the link in a new tab instead, it doesn't work. That is, the Javascript disables opening the link in a new tab and just does the same window.history code. Specifically, this is when you hold down COMMAND + CLICK on Mac. What is the best way to not preventDefault when a key is pressed?

Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118

1 Answers1

1

use event.ctrlKey, shiftKey, altKey, metaKey

Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118