I tried to print something using window.print();
However, when I click my trigger button for the second time, the window print appear again after I click on close button.
After the code runs until $('#main').show(); , it goes back to window.print(); again. And if I tried for the third time, it will reload the window print 3 times and so on. I'm not sure how to terminate the query after I close the window.
This is my js code;
self.QrCode = ko.observable("../Content/img/qr-code (1).png");
self.GetQrCode = function (obj) {
var ID = obj.Id;
$.ajax({
url: '/QC/GetQrCode',
cache: false,
type: 'GET',
contentType: 'application/json; charset=utf-8',
data: { rejectsId: ID },
success: function (rejectsId) {
self.QrCode(rejectsId.QRCode);
self.PrintQrCode();
}
});
}
self.PrintQrCode = function (obj) {
$('#main').hide();
$('#QrCodePrint').show();
$("#test").on("load", function () {
window.print();
$('#QrCodePrint').hide();
$('#main').show();
});