Last active
May 23, 2020 15:04
-
-
Save lazzyms/a351bfb52179df3c10137d52719e9ff1 to your computer and use it in GitHub Desktop.
To get all the email from links with 'mailto' action with javascript.
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 links = document.getElementsByTagName('a'), hrefs = [], sendIt = ''; | |
for (var i = 0; i<links.length; i++) | |
{ | |
if(links[i].href.includes('mailto')) { | |
var email = links[i].href.replace('mailto:',''); | |
//If you want to use this as array | |
hrefs.push(email); | |
//If you want to copy all email ids in one string (usually to send mail to multiple ids at once) | |
sendIt += email + ', '; | |
} | |
} | |
// Auto-Copy e-mail from string | |
var el = document.createElement('textarea'); | |
el.value = sendIt; | |
el.setAttribute('readonly', ''); | |
el.style = {display: 'none'}; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment