I have the need to provide the ability to print a label on successful save and after the print redirect to a search page. This works in chrome, firefox, ie, iOS 6/7 safari, etc.
You can use window.matchMedia (caniuse link), combined with window.onbeforeprint and window.onafterprint (for earlier IE support). A good reference for using matchMedia can be found here and here.
To satisfy using matchMedia with iOS, use nested events. First, listen for the media type to change to print. Then, inside that callback, listen for the media to change back to screen.
if (window.matchMedia) {
var printQuery = window.matchMedia('print');
printQuery.addListener(function() {
var screenQuery = window.matchMedia('screen');
screenQuery.addListener(function() {
//actions after print dialog close here
});
});
}