I know that you can open a new tab in javascript and subsequently close it if you keep a reference to it as per this SO question.
In my case, I want to open a new tab, which contains a script that automatically triggers the browser's print dialog. Once the print dialog is dismissed, I want the new tab to go away. Since the scripts in the new page were not what created that page, they don't have the ability to close it.
Is there a way to detect when the print dialog is dismissed so that the script that created the new tab knows when to close it?
Example of what I'm trying to accomplish:
var printTab;
$('#print_me').on('click', null, function() {
printTab = window.open($('#print_me').data('target'), "_blank");
printTab.focus();
});
function closePrintTab() {
printTab.close();
}
/* Here is the sketchy part; what triggers a call to closePrintTab? */