Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
nw.js cierra la ventana después de usarlo para imprimir

Estoy imprimiendo datos desde una nueva ventana, después de lo cual quiero cerrar la ventana. Si cierro la ventana de inmediato, entonces no tiene tiempo suficiente para que se ejecute la función javascript que escribe datos en el documento. Estoy usando setTimeout para imitar este comportamiento. Sin embargo, me pregunto si hay una forma nativa de hacer esto.

Por razones obvias, establecer el tiempo de espera no es una solución óptima, ya que muchas cosas podrían bloquear la ejecución, etc., tal vez una devolución de llamada de la función de print sería suficiente, aunque los documentos no mencionan nada al respecto. Aquí está mi código:

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

Y en el 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 answers
Answer question

0

¿Mover window.close() al evento onafterprint ?

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!