Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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 Respuestas
Responde la pregunta

0

Add href="#" in the anchor tag.

Example:

<a id="printButton" onclick="print()" title="Print" href="#"></a>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda