i hope i could find any help here, i am working on a html/js, jquery projects and trying to catch the afterprint event and it's working fine, the problem is that i have two separates pages and the two have a printing need in them, so when i close the print preview in one page, it's triggers both event of the two pages. this is the function i used in the two pages :
(function () {
var globalUrl = '@Url.Content("~/")';
var afterPrint = function () {
setTimeout(function () {
$.confirm({
title: 'Confirmation',
content: "<div><span class='printing-message'>" + "L'impression doit être collée sur votre colis" + "</span></div>",
backgroundDismiss: false,
backgroundDismissAnimation: 'shake',
buttons: {
OK: {
action: function () {
this.close();
window.location = globalUrl + "Colis/MyDeliveryRequests";
}
}
}
});
}, 500);
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function (mql) {
if (!mql.matches) {
afterPrint();
}
});
}
window.onafterprint = afterPrint;
}());