I'm trying to open a new tab by detecting a control key during a click. I know the logic, but whenever I have it in place - the control key is not detected, and instead the browser inspector menu opens.
function handleClick(event) {
event.preventDefault()
if (event.ctrlKey) {
return window.open('www.google.com', '_blank')
}
return window.open('www.google.com', '_self')
}
The element where the onClick is detected was a button. I've also tried with an anchor tag. Both have the same behavior. I've also tried:
function handleClick(event) {
event.preventDefault()
if (event.keyCode === 17) {
return window.open('www.google.com', '_blank')
}
return window.open('www.google.com', '_self')
}
This will work but it's for the shift key:
function handleClick(event) {
event.preventDefault()
if (event.shiftKey) {
return window.open('www.google.com', '_blank')
}
return window.open('www.google.com', '_self')
}