admin管理员组

文章数量:1430941

Is there a simple solution without jquery, inside HTML-tags to catch a CTRL+Mouseclick?

It could look like this:

<a href="#" onclick="if(ctrl_is_pressed()) alert('CTRL+Mouseclick');">X</a>

Is there a simple solution without jquery, inside HTML-tags to catch a CTRL+Mouseclick?

It could look like this:

<a href="#" onclick="if(ctrl_is_pressed()) alert('CTRL+Mouseclick');">X</a>
Share Improve this question asked Sep 9, 2013 at 14:05 rubo77rubo77 21k33 gold badges148 silver badges240 bronze badges 2
  • 2 I asume this is to prevent the anchor opening in a new tab/window. Unless you have a very good reason for this, dont change browser behaviour. It will hurt the user experience more than it does any good – Martijn Commented Sep 9, 2013 at 14:13
  • I want to use the X as a close button, except in case CTRL is pressed too – rubo77 Commented Sep 9, 2013 at 16:57
Add a ment  | 

1 Answer 1

Reset to default 7

In the event object, there's a ctrlKey property.

<a href="#" onclick="if(event.ctrlKey) alert('CTRL+Mouseclick');">X</a>

本文标签: javascriptCatch onclickevent with CTRL pressedStack Overflow