<script type="text/javascript"> window.print(); window.onafterprint = window.close; </script>
<script type="text/javascript"> window.print(); window.onafterprint = () => alert("print dialog closed."); </script>