[removed] and [removed] get fired at the same time

前端 未结 3 1728
挽巷
挽巷 2021-01-05 09:51

I have defined onbeforeprint and I modify my html code and now once I finish printing that is on select of print button I want the onafterprint to

3条回答
  •  盖世英雄少女心
    2021-01-05 10:00

    I ran into this same issue trying to use the onafterprint event, even in modern browsers.

    Based on one of the other answers here, I was able to come up with this solution. It let's me close the window after the print dialog is closed:

    // When the new window opens, immediately launch a print command,
    // then queue up a window close action that will hang while the print dialog is still open.
    // So far works in every browser tested(2020-09-22): IE/Chrome/Edge/Firefox
    window.print();
    setTimeout(function () {
        window.close(); // Replace this line with your own 'afterprint' logic.
    }, 2000);
    

提交回复
热议问题