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

258
Vistas
How can I copy a value to clipboard in javascript without using HTML?

I am trying to copy the value of 'longlat' to clipboard automatically without having to press a button in HTML. I have tried clipboards and Clipboard.JS but have not been able to find a solution to doing this without HTML or getting some error.

 const clipboardy = (...args) => import('clipboardy').then(({default: clipboardy}) => clipboardy(...args));
  const puppeteer = require("puppeteer");
 
  const url = "https://www.google.com/";
  
  async function StartScraping() {
    await puppeteer
      .launch({
        headless: false,
      })
      .then(async (browser) => {
        const page = await browser.newPage();
  
        await page.setViewport({
          width: 2000,
          height: 800,
        });
  
        page.on("response", async (response) => {
  
         
          if (response.url().includes("Start")) {
            const location = await response.text() 
            let intlong = location.indexOf("Example:")
            const longlat = location.substring(intlong , intlong + 46)
           
            console.log(longlat);



            copyData(longlat)
            
            }
  
        });
  
        await page.goto(url, {
          waitUntil: "load",
          timeout: 0,
        });
      });
  }

function copyData(data1) {
  
  clipboard.writeSync(data1)
}



  StartScraping();

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use javascript's navigator to copy to clipboard any text, like below

navigator.clipboard.writeText("String to be copied!");

create a function to copy and use it.

function copy(text) {
  /* Copy the text inside the text field */
  navigator.clipboard.writeText(text);
  
  /* Alert the copied text */
  alert("Copied the text: " + text);
}

copy("Hello, I'll be copied!");

about 4 years ago · Juan Pablo Isaza Denunciar
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