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

90
Visualizações
content only appears if print is called twice javascript

I'm currently trying be able to print something to the screen using javascript. Right now, I've got a simple print function set up like below that gets triggered on a link press in HTML.

   function print() {
        console.log(printImgURL);
        let w = window.open();
        w.document.write(`<img src="${printImgURL}">`);
        w.focus();
        w.print();
        w.close();
    }
<a id="printButton" onclick="print()"title="Print"></a>

The content only appears when the link is pressed the second time (and any other time after), Although the console.log statement shows the proper URL to the image regardless if the image actually appears in the print dialogue or not. Does anyone have any idea why the content wouldn't be showing up the first the link is pressed?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Add href="#" in the anchor tag.

Example:

<a id="printButton" onclick="print()" title="Print" href="#"></a>
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