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

172
Views
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 answers
Answer question

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 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!