Last active
December 15, 2015 12:39
-
-
Save ronnyandre/5261967 to your computer and use it in GitHub Desktop.
Don't prevent events when users hold CTRL or META keys
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
document.getElementById("myLink").addEventListener("click", function(e) { | |
// e.preventDefault(); (bad) | |
if(e.meta || e.ctrlKey) return; // Don't block user if they want to open a new tab | |
e.preventDefault(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment