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

215
Visualizações
Button click not working after document is printed javascript

I have a div that contains text to be printed on external printers.

<div id="school">
<p>Who loves school?</p>
 <img onClick=clickMe(1) src='clickImage.png' />
</div>

Below is the javascript that handles the click of the above image button and initiates a printing dialog,

  function clickMe(id) {
    const printContents = document.getElementById(id).innerHTML;
            const originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
  }

The above javascript prints the div successfully, but with only 1 problem. After the print dialog exits, the image button stops responding to clicks until the page is refreshed.

Ideal behavior would be the button responding on each click without the need to refresh the page.

What am I missing?

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