我也遇到过同样的问题,我的调查显示
onfocus
(或
电子稳定控制系统
按钮)关闭确认对话框。
聚焦事件
function safariPrint() {
// Safari 12, macOS
if (!window.onafterprint) {
const onAfterPrint = mql => {
if (!mql.matches) {
showStuff();
// printing is finished => unsubscribe to avoid leaks
if (mediaQueryList.removeEventListener) {
mediaQueryList.removeEventListener('change', onAfterPrint);
} else {
mediaQueryList.removeListener(onAfterPrint);
}
}
window.onfocus = null;
};
// a tiny polyfill for a plain onafterprint
// to handle standard window.print() dialog events
const mediaQueryList = window.matchMedia('print');
if (mediaQueryList.addEventListener) {
mediaQueryList.addEventListener('change', onAfterPrint);
} else {
mediaQueryList.addListener(onAfterPrint);
}
// if a user cancels printing in Safari's print confirmation dialog
// then we will trigger a cleanup
window.focus();
window.onfocus = () => {
onAfterPrint(mediaQueryList);
};
}
hideStuff();
window.print();
}