Skip to content

Instantly share code, notes, and snippets.

@scsskid
Last active August 29, 2020 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scsskid/a27c15370b065679beeadf5806454ca9 to your computer and use it in GitHub Desktop.
Save scsskid/a27c15370b065679beeadf5806454ca9 to your computer and use it in GitHub Desktop.
window.open with working CMD/ctrl key (open in new tab funcionality)
//src: https://davidwalsh.name/window-open
someElement.addEventListener('click', function(e) {
var url = someElement.get('data-url');
if(e.metaKey || e.ctrlKey || e.button === 1) {
window.open(url);
}
else {
window.location = url;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment