Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda