0

I want to make an check in JavaScript for checking of the CTRL button is clicked. My php:

<tr class="clickable" onclick="gotolink('<?= base_url() . invoices/createinvoice/' . $customer->Id; ?>')">

my JS code:

function gotolink(url) {
        if (HERE THE CHECK FOR THE CTRL BUTTON){
           window.open(url,'_blank');
        }
        else{
            location.href = url;
        }
    }

I don't know how to make the check. Could you help me?

1 Answers1

0

function gotolink(url, event) {
  console.log(event.ctrlKey);
  if (event.ctrlKey) {
    window.open(url, '_blank');
  }
}
<button onclick="gotolink('google.com',event)">test</button>
n4m31ess_c0d3r
  • 3,028
  • 5
  • 26
  • 35
Satish
  • 696
  • 1
  • 11
  • 22