Quiero que se copie el texto en el portapapeles con JavaScript, que funciona tanto en el teléfono como en el escritorio.
Tengo el siguiente código y funciona solo para escritorio, no para dispositivos móviles.
<input type="text" value="Hello World" id="myInput"> <button onclick="myFunction()">Copy text</button> <script> function myFunction() { /* Get the text field */ var copyText = document.getElementById("myInput"); /* Select the text field */ copyText.select(); copyText.setSelectionRange(0, 99999); /* For mobile devices */ /* Copy the text inside the text field */ navigator.clipboard.writeText(copyText.value); /* Alert the copied text */ alert("Copied the text: " + copyText.value); } </script>