1

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
empiric
  • 7,825
  • 7
  • 37
  • 48

2 Answers2

2

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 .
}
4b0
  • 21,981
  • 30
  • 95
  • 142
  • 2
    Thanks @shree. its worked but after close print window not call function.when i move other tab window and come back to that tab window its working. – Sasindu Jayampathi Sep 30 '19 at 07:00
  • `onPrintDialogClose` have some issues. It's not compatible with all browser. [See git hub issues about this. They are still pending](https://github.com/crabbly/Print.js/issues). It's plugin issue not your's. – 4b0 Sep 30 '19 at 07:13
2

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

  }

});
Menna Ramadan
  • 465
  • 3
  • 12