Sasindu Jayampathi
Sasindu Jayampathi

Reputation: 362

Is there anyway to wait for print window to close in print.js

I have some jquery code using print.js for printing an element and its working fine but I need to know if I can check if the print window is closed and reload the page

printJS('print_paper', 'html');
//do stuff after close print window

Upvotes: 1

Views: 2022

Answers (2)

Menna Ramadan
Menna Ramadan

Reputation: 485

I tried slebetman's solution in the following link https://github.com/crabbly/Print.js/issues/348 and it works fine with me

let focuser = setInterval(() => window.dispatchEvent(new Event('focus')), 500);

printJs({

    printable: url,

   onPrintDialogClose: () => {

   clearInterval(focuser);

   // do your thing..

},

onError: () => {

   clearInterval(focuser);

    // do your thing..

  }

});

Upvotes: 2

4b0
4b0

Reputation: 22323

There is a option called onPrintDialogClose which is fire after Print dialog close.

printJS({
    type: "html",  // Include other option if needed like style , css .....
    onPrintDialogClose: closedWindow 
  });
}

function closedWindow() {
  alert("Window is closed "); // What ever you want to do after window is closed .
}

Upvotes: 2

Related Questions