Copying an email address using document.execCommand(“copy”)

Tags:



function copy(){
    var email = "abc@dfg.ca";
    email.select();
    document.execCommand("Copy");
};

The above code does not copy the email address.

Answer

Check the snippet, this may help you

function copyEmail(){
    var email = document.getElementById('email');
    email.select();
    document.execCommand('copy')
};
<input type="email" id="email"/>
<input type="button" value="copy"  onClick="copyEmail()"/>


Source: stackoverflow