2

I am using PrintArea and I want to handle 'Close' event of Print dialog box(Chrome, Firefox,...). I have tried

window.onclose = function(){
   // do something
}

but it did not work.

Is there any way to do it?

Any solution is appreciated.

Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53

2 Answers2

0
window.print() //or whatever you want to do
window.onfocus=function(){
//user is back
}
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

Do this

window.print() //open the print dialog box
window.onafterprint=function(){
    //do whatever it is you wish to do
}

Note

This only works for Firefox (>6.0) and Internet Explorer.

For other browsers including Chrome, try window.matchMedia()

window.print() //open the print dialog box
var printEvent = window.matchMedia('print');
printEvent.addListener(function(printEnd) {
    if (!printEnd.matches) {
        // do whatever you wish to do
    };
});
Shea Hunter Belsky
  • 2,815
  • 3
  • 22
  • 31