Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge browser: Prevent Ctrl + leftclick

Is there a way to prevent the default behaviour of the Microsoft Edge browser, when I use Ctrl + Left click on a link?

Edge is opening the link in a new tab, but I want to have my own event for Ctrl + Left click.

like image 480
Tream Avatar asked Jul 16 '26 18:07

Tream


1 Answers

You can assign a click event handler to your links.
Then, in a handler, you can do e.preventDefault() in order to prevent default browser action. e.ctrlKey will tell you if Ctrl button is clicked.

$("a").click(function(e) {
  if (e.ctrlKey === true)
  {
    e.preventDefault();
    // your custom actions
  }
});

Here is the working JSFiddle demo.

Since you have defined a jquery tag, I have used this. Of course, it can be easily done in vanilla JS.

like image 113
Yeldar Kurmangaliyev Avatar answered Jul 18 '26 06:07

Yeldar Kurmangaliyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!