Estoy tratando de escribir en javascript y quiero entender por qué no funciona. ejemplo de código de pedido que quiero copiar: 593004485164756431
cuando copio al portapapeles: 593004485164756500
Revisé si hay un error en la consola, no hubo ningún error, ¿el navegador afecta el error? yo uso firefox
este es mi codigo
function copyToClipboard(text) { if (navigator.clipboard && window.isSecureContext) { return navigator.clipboard.writeText(text) } else { // text area method let textArea = document.createElement("textarea") textArea.value = text // make the textarea out of viewport textArea.style.position = "fixed" textArea.style.left = "-999999px" textArea.style.top = "-999999px" document.body.appendChild(textArea) textArea.focus() textArea.select() return new Promise((res, rej) => { // here the magic happens document.execCommand('copy') ? res() : rej() textArea.remove() }) } }en el botón
<img onclick="copyToClipboard({{ $result['code_order'] }})" style="width:20px;cursor:pointer;" src="{{ url('img/copy-solid.svg') }}"/>Espero poder encontrar la solución a este problema. Gracias