I need to copy my e-mail address to a clipboard if user has no email client defined. i found a solution somewhere on the web:
html:
<input type="text" value="someemail@gmail.com" id="myInput" style="display:none";>
js:
function copyEmail() {
var copyText = document.getElementById("myInput");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999);
/* Copy the text inside the text field */
document.execCommand('copy');
/* Alert the copied text */
alert("You don't have an email client defined" + '\n' + "Email address copied: " + copyText.value + ".");
}
$('a[href^=mailto]').each(function() {
var href = $(this).attr('href');
$(this).click(function() {
var t;
var self = $(this);
$(window).blur(function() {
// The browser apparently responded, so stop the timeout.
clearTimeout(t);
});
t = setTimeout(function() { copyEmail() }, 1);
});
});
it gets the value, but it doesn't copy it to the clipboard. What am I doing wrong?