Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!