Using document.execCommand('copy') in mobile

Viewed 5639

Is there a way to copy to mobile clipboard? I've been researching for days but haven't found a good solution. Clipboard.js doesn't seem to work on mobile, giving me an error "no support :("

I'm currently using the following function:

function copytext(text) {
    var textField = document.createElement('textarea');
    textField.innerText = text;
    document.body.appendChild(textField);
    textField.select();
    document.execCommand('copy');
    textField.remove();
}

Works like a charm on chrome on my desktop. But on chrome mobile, nothing gets copied.

Is there a solution out there?

1 Answers
Related