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

369
Visualizações
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 à 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