Last active
May 31, 2016 14:05
-
-
Save mcbrwr/529b7b4b0128c16c43dc to your computer and use it in GitHub Desktop.
vanilla JS to open href of a link in popup window (ie for custom share buttons)
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
var elements = document.querySelectorAll('.socialshares a'); | |
Array.prototype.forEach.call(elements, function(el, i){ | |
el.onclick = function(elaction) { | |
elaction.preventDefault(); | |
window.open( el.attributes.href.value, '', 'width=600,height=300' ); | |
} | |
}); |
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.addEventListener('DOMContentLoaded', function() { | |
[].forEach.call(document.querySelectorAll('.puw'), function(el) { | |
el.addEventListener('click', function(e) { | |
if (e.target.nodeName.toLowerCase() == 'a') { | |
e.preventDefault(); | |
} | |
window.open( e.target.href, '', 'width=600,height=300' ); | |
}); | |
}); | |
}); |
Author
mcbrwr
commented
Jan 19, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment