Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
Copy to clipboard code in JavaScript doesn't work

I'm trying to write in javascript and I want to understand why it doesn't work? sample order code that I want to copy: 593004485164756431

when I copy to clipboard : 593004485164756500

I checked for an error in the console, there was no error, does the browser affect the error? i use firefox

this my code

                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()
                    })
                }
            }

on button

<img onclick="copyToClipboard({{ $result['code_order'] }})" style="width:20px;cursor:pointer;" src="{{ url('img/copy-solid.svg') }}"/>

I hope I can find the solution to this problem. Thank you

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda