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

234
Views
How do I copy text and paste it to an external element?

I'm building a site for my org that generates templates for users

I am able to copy a chosen template to the user's clipboard like so:

function copyTemplateText(){
    let text_to_copy = document.getElementById("templateText").innerHTML;

    if (!navigator.clipboard){
        // Pass
    } else{
        navigator.clipboard.writeText(text_to_copy).then(
          function(){
            console.log('copied'); // success 
          })
        .catch(
           function() {
            console.log('not copied');// fail 
        });
    }

This template would need to be pasted into the text area of an external website. Granted, users just need to CTRL+V and be done with it, but I was wondering if this can be done automatically. How can I pass a function from my site, to this new one? Is this possible?

Pseudo Code:

copyTemplateText('..runs');
let pasteHere = document.getElementByID('textBox');
pasteHere.innerText = What's in the clipboard;

I tried doing it with sessionStorage:

navigator.clipboard.readText().then(clipText =>
    sessionStorage.setItem("clipboard", clipText));
let pasteHere = document.getElementById("textBox");
pasteHere.innerText = sessionStorage.getItem("clipboard");

But that doesn't work. I get:

Uncaught TypeError: Cannot set properties of null (setting 'innerText || innerHTML')
    at HTMLAnchorElement.pasteTicketTemplate
Uncaught (in promise) DOMException: Document is not focused.

Is what I'm trying to do feasible? If so, how would I go about this?

Thanks a bunch!

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