Skip to content
Advertisement

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

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

The above code does not copy the email address.

Advertisement

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()"/>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement