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?
The Clipboard API can be used instead of execCommand in many cases, but execCommand is still sometimes useful.
The execCommand() method is deprecated. Do NOT use it. The applets property returns an empty HTMLCollection in all new browsers. The <applet> element is not supported in HTML5.
Copying Text to the ClipboardCTRL+C to copy. CTRL+X to cut. CTRL+V to paste.
According to MDN, document.execCommand('copy')
is available in the following mobile browsers:
Note that this does not include the iOS Chrome or Firefox, which per-Apple's requirement, both must use the iOS supplied WebKit. Until iOS Safari supports it, iOS Chrome and iOS Firefox probably cannot.
Update:
Safari on iOS 10+ supports cut and copy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With