-5

Note :- Here Check = Cheque ( In USA cheque is spelled as check )

In a website, we've given the functionality to print the check to super-admin.

Super-admin can print the check by clicking on print button. After clicking on the print button, it generates a popup to complete the action. Also, there are two events named as print and cancel(This is browser specific).

When super-admin clicks on the print event, then check comes out with all the details and all the orders belonging to the same check will get paid automatically in DB. When super-admin clicks on cancel, there is no action to be performed.

What we need to do :- We need to capture the event of print and cancel with 100% accuracy in all browsers, because here it's the matter of money (check).

So, I Need help on the way to get cancel and print events.

phoenix
  • 3,069
  • 3
  • 22
  • 29
  • This is going to be hard/impossible to achieve. There are two events for printing, `onbeforeprint` and `onafterprint`. Neither are well supported, and neither will tell you if the print was successful or was cancelled. Therefore I don't believe what you require is possible using JS alone. – Rory McCrossan Feb 11 '16 at 08:48
  • You can refer this link (http://stackoverflow.com/questions/297482/capturing-print-event-via-jquery) or (http://stackoverflow.com/questions/534977/javascript-event-handler-for-print) – ChayanC Feb 11 '16 at 08:59

2 Answers2

0

Why not just call the print() function from within an other function?

Like:

function myPrint() {
  $("#myDiv").css({"border-color":"red"});
  window.print();
}

Then you could call it from where you need it.

ChayanC
  • 201
  • 7
  • 29
0

if you need to capture the print event you can use the beforeprint javascript event

Using addEventListener():

window.addEventListener('beforeprint', (event) => {
  console.log('Before print');
});

Using the onbeforeprint event handler property:

window.onbeforeprint = (event) => {
  console.log('Before print');
};

https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeprint_event

DavesPlanet
  • 576
  • 5
  • 14