I've been printing my page using the code below:
window.print();
An image below is what the print preview in Google chrome browser looks like. It has two main buttons: print
and cancel
.
I want to know if the user has clicked the print
or cancel
buttons. What I did uses jquery:
HTML Code of the Print Preview:
<button class="print default" i18n-content="printButton">Print</button>
<button class="cancel" i18n-content="cancel">Cancel</button>
Jquery Code:
$('button > .cancel').click(function (e) {
alert('Cancel');
});
$('button > .print').click(function (e) {
alert('Print');
});
I tried the code above with no luck. What am I missing?
This should do the trick. I've used jQuery v2.2.0 which is included in the html file.
I guess this might as well be used as a way to print certain divs in your html. Just hide the
body
element and only show the div that you want to print with some positioning css. Hope it works in yours. I've tried it and I can say that it worked for me.You can not access Chrome's internal windows (printing dialog in this case) directly from a regular web page.
Or, If you want to do something when the print preview gets opened, you can try below:
Reference: How to capture the click event on the default print menu called by Javascript window.print()
Maybe if you provide your requirements for this two buttons click event, we can provide you an alternate solution.
it is very easily possible:
The myFunction() that you can define within a tag will be fire when either the printing job is done or the cancel button was pressed.
As far as I know, the print preview is not part of any
document
your JS can access. These might interest you:Detecting browser print event
ExtJS 4 - detecting if the user pressed "Print" on the print dialog that was called programatically