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

187
Visualizações
How To Use A Button To Copy To Clipboard

I am building a browser extension (mainly for chrome).

I have successfully created other features except the copy to clipboad button. I have been on this for hours and it ends up in "Uncaught (in promise) DOMException: Document not in focus. Kindly let me know what I am doing wrong: NB(I removed some parts of code not needed for this question)

HTML and JS:

    <button id="input-btn" >Save Input</button>
    <button id="save-tab" >Save Tab</button>
    <button id="delete-btn" >Delete All</button>
    <button id="copy-btn" onclick="copyFunc()">Copy All</button>
    
    <ul id="ul"> </ul>```

//Javascript


let leads = []
const inputEl = document.getElementById("input-el") 
const inputBtn = document.getElementById("input-btn") // Using const since these two will not be reassigned later
const ulEl = document.getElementById("ul") //Grabbing the unorderd list from html

const deleteButton = document.getElementById("delete-btn") //Fetch the delet bttn from html

const fetchedLocalStrorage = JSON.parse (  localStorage.getItem("leads") )  //Fetch items from local storage and parsing it out to become an array again
const tabButton = document.getElementById("save-tab")

//Copy to clipboard function

function copyFunc() { 
      
        render(leads)

        /* Copy the text inside the listed items */
        navigator.clipboard.writeText(ulEl.textContent)
       
       /* Alert the copied text */
       alert("Copied to Clipboard");
     }


//Making the input button active

inputBtn.addEventListener("click", function(){

    leads.push(inputEl.value)
    inputEl.value = ""

    localStorage.setItem("leads", JSON.stringify(leads))

    render(leads)
    }

)



function render (leads){
    let listItems = ""

//loop through the array and give the result

for (let i = 0; i<leads.length; i ++ ) {
    listItems += `
    <li> 
        <a target='_blank' href= '${leads[i]}'>
         ${leads[i]}
        </a>
    </li>
    `
}

    ulEl.innerHTML = listItems

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