Created
August 27, 2014 17:52
-
-
Save travismillerweb/2862eb8bacbbd3cc3da4 to your computer and use it in GitHub Desktop.
JS - Redirects & window.open script
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
/* | |
JS - Redirects & window.open script | |
Reference URL: http://davidwalsh.name/window-open | |
(Thanks David Walsh!) | |
*/ | |
someElement.addEventListener('click', function(e) { | |
var url = someElement.get('data-url'); | |
if(e.metaKey || e.ctrlKey) { | |
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