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

367
Vistas
Is there any alternative to window.open to print a PDF? (dialog to print the PDF)

I have to open a PDF and ask to print it automatically. I did this:

const pdfWindow = window.open("generate_pdf.php?id="+id, "_blank");
if (!pdfWindow) {
    alert("You have to enable popups");
} else {
    pdfWindow.addEventListener("load", function () {
        pdfWindow.print();
    }, false);
}

this is working correctly, window.open opens the link that output the PDF, then when the page loaded, it calls pdfWindow.print(); that open the dialog to print the PDF.

The problem is that browsers default have popup disabled. So most users will see "You have to enable popups" alert, because window.open will fails. I know popups can be easily enabled, but this is not nice for most users :(

Is there an other solution instead of window.open to: Open "generate_pdf.php". Then, when "generate_pdf.php" generated the PDF, automatically ask to print it.

I used window.open because user should to remain on the main page.

Edit: The reason why I have to automatically open the print dialog is because I want to be sure that operators will not forget to print the PDF

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