Using document.execCommand ('copy') on mobile devices

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

I am 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 is copied.

Is there a solution there?

+5
source share
1 answer

According to MDN , document.execCommand('copy') is available in the following mobile browsers:

  • Chrome for Android 42+
  • Firefox Mobile (Gecko) 41+

Please note that this does not include iOS Chrome or Firefox, each of which requires the use of iOS supplied by WebKit. While iOS Safari doesn't support it, iOS Chrome and iOS Firefox probably can't.

Update:

Safari on iOS 10+ supports cutting and copying

+4
source

Source: https://habr.com/ru/post/1245039/


All Articles