question

MommyAiraa-3888 avatar image
0 Votes"
MommyAiraa-3888 asked RenaNi-MSFT commented

window.print(); Repeating

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();
     });



dotnet-aspnet-core-general
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MommyAiraa-3888 ,load event will always be triggered if your id="test" element load anything. You need check if your test element load anything when you click the button.Also, share more code will be more helpful.

0 Votes 0 ·

Hi,

this is my js script:

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);
//$("#test").attr('src', rejectsId.QRCode);
self.PrintQrCode();
}
});
}


 self.PrintQrCode = function (obj) {
     $('#main').hide();
     $('#QrCodePrint').show();
     $("#test").on("load", function () {
         window.print();
         //return false; 
         $('#QrCodePrint').hide();
         $('#main').show();
     });
 }

0 Votes 0 ·

Hi @MommyAiraa-3888 , Also remember to share your html code here.

0 Votes 0 ·
Show more comments

0 Answers