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

166
Visualizações
nw.js close window after using it to print

I am printing data from a new window after which I want to close the window. If I close the window straight away then it doesn't have enough time for the javascript function to run which writes data to the document. I am using setTimeout to mimic this behaviour. However, I am wondering if there is a native way to do this.

For obvious reasons setting time out isn't an optimal solution as many things could block execution etc - perhaps a callback from the print function would do the trick, docs do not mention anything about it though. Here's my code:

nw.Window.open('print.html', {show: false, new_instance: false}, function(new_win) {
    new_win.on('loaded', function() {
      this.print({autoprint: true, headerFooterEnabled: false});
        });
    });

And in the print.html:

var div = document.getElementById("orderBill");
div.innerHTML = '<h1>Header</h1><p>Some text</p>';
var win = nw.Window.get();
setTimeout(function(){ win.close(); }, 5000);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Move the window.close() to the onafterprint event?

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onafterprint

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