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?
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?
Share edited Mar 31, 2016 at 18:18 Zeno Rocha 3,5961 gold badge25 silver badges27 bronze badges asked Mar 14, 2016 at 19:33 Jackson CunninghamJackson Cunningham 5,0933 gold badges35 silver badges84 bronze badges 5- 1 What version of Chrome and what mobile device? It's supposedly available in mobile Chrome 42+ and mobile Firefox 41+, presumably both Android. – Alexander O'Mara Commented Mar 14, 2016 at 19:37
- Weird. I'm on the most recent version. Here's a live page with the copy link button: trailerpuppy./trailers/… – Jackson Cunningham Commented Mar 14, 2016 at 19:40
- 1 Working on my end, Chrome 49.0.* for Android. I'm guessing you're using iOS Chrome? – Alexander O'Mara Commented Mar 14, 2016 at 19:44
- Ah.. yeah I think my version may be outdated. It was the most recent version available on my iOS version.. But I need to update iOS. Thanks for troubleshooting. – Jackson Cunningham Commented Mar 14, 2016 at 19:45
- Chrome for iOS is basically just an alternative app for the same rendering and JavaScript API as the built-in WebKit for Safari. Unless iOS Safari supports it, iOS Chrome and Firefox probably won't either. – Alexander O'Mara Commented Mar 14, 2016 at 19:47
1 Answer
Reset to default 4According to MDN, document.execCommand('copy')
is available in the following mobile browsers:
- Chrome for Android 42+
- Firefox Mobile (Gecko) 41+
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