I am facing an issue with the print function on my web page. I want to display a thank you message to the user after they have either printed or cancelled the print dialog.
Below is a simplified version of the print function code:
function printThenThank() {
window.print();
$('.thankYou').removeClass('hidden');
// alert('debug message');
}
The problem I'm encountering is that sometimes the "hidden" thank you message appears in the printout, while other times it does not. I have tested it multiple times by including debug messages before and after the print request is made.
Initially, I thought window.print()
was a synchronous call, but it seems to work more like an asynchronous trigger for a process involving a modal dialog.
Is there a reliable cross-platform method to ensure that the desired content changes are only implemented once the user has chosen to print or cancel from the window.print() dialog?