Skip to content

Instantly share code, notes, and snippets.

@lazzyms
Last active May 23, 2020 15:04
Show Gist options
  • Save lazzyms/a351bfb52179df3c10137d52719e9ff1 to your computer and use it in GitHub Desktop.
Save lazzyms/a351bfb52179df3c10137d52719e9ff1 to your computer and use it in GitHub Desktop.
To get all the email from links with 'mailto' action with javascript.
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