How to disable <a onclick> when the user holds control

Usually, when people click on a link, I get attached to it. And then return false.

When people press "control", they expect a new page to open. So I want to ignore onclick AND / OR. How to do it?

+3
source share
3 answers

The object eventhas a logical flag ctrlKey, so you can check this in your handler. It depends a little on your structure, but as a rule, if your handler returns false, then you will be “defeated” by clicking.

IE event (.. "window" ). . , :

function clickHandler(theEvent) {
  theEvent = theEvent || window.event;
  // ...
}
+5

OnMouseDown.

0

You can hook on the OnKeyPress event and check if the control key is pressed. If so, raise the flag that is used in OnClick. If the flag is raised, then skip all the normal OnClik code and place it on the other, do what you need.

0
source

Source: https://habr.com/ru/post/1741338/


All Articles