Last active
July 2, 2018 10:48
-
-
Save arjshiv/8567d38689d322a60eb9 to your computer and use it in GitHub Desktop.
jQuery event handler - Detect control click (Ctrl+click) on Windows/ command + click (Cmd+click) on Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clickHandler (event) { | |
if (event.ctrlKey || event.metaKey) { | |
//ctrlKey to detect ctrl + click | |
//metaKey to detect command + click on MacOS | |
executeCtrlClickActionHere(); | |
} else { | |
executeRegularClickActionHere(); | |
} | |
}; |
Why do you need to read the event.ctrlKey
?
According to MDN, MouseEvent.metaKey
is quite enough.
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know this is older, but it just got me where I was going. Thank you!