admin管理员组文章数量:1410731
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
本文标签: javascriptUsing documentexecCommand(39copy39) in mobileStack Overflow
版权声明:本文标题:javascript - Using document.execCommand('copy') in mobile - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745046675a2639406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论