Is there a way to find out when printing ends using JQuery. I don't want to find when the printing window is closed but when the actual printing is done. My problem is , when the user prints a page on my web app and quickly navigates from the page, the printing gets cut off and does not give the entire print result.(I was thinking if I could block the UI till the actual printing ends, it would resolve the issue).
Is there a way to find out when printing ends using JQuery. I don't want to find when the printing window is closed but when the actual printing is done. My problem is , when the user prints a page on my web app and quickly navigates from the page, the printing gets cut off and does not give the entire print result.(I was thinking if I could block the UI till the actual printing ends, it would resolve the issue).
window.onafterprint
event: stackoverflow./questions/18325025/…
– Daniel Beck
Commented
Mar 30, 2016 at 19:32
You can use a bination of window.onafterprint
(supported by IE 5+ and FireFox 6+) and use window.matchMedia
(supported by Chrome 9+ and Safari 5.1+). Unfortunately Opera doesn't support either. Here's an article that goes into detail about the approach.
Here's the code just in case the link bees deactivated:
(function() {
var beforePrint = function() {
console.log('Functionality to run before printing.');
};
var afterPrint = function() {
console.log('Functionality to run after printing');
};
// supported by Chrome 9+ and Safari 5.1+
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
// supported by IE 5+ and FireFox 6+
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
No there isn't. The jQuery http://api.jquery. API link doesn't list any printer methods. Sorry, but you're out of luck trying to access both the Mac & the Windows printer queues via jQuery. The queues are part of the operating systems & not web browsers (OS applications). So unless you're working with C or C++ or Java, there isn't a way to build an events bridge back from the printer queues to multiple browsers.
Not only that, but Microsoft & Apple would have to support multiple 3rd party panies, like Google. They're not likely to do that, when they have their own web browsers, eg. IE & Safari, respectively. The way that free web browsers work is that they attempt to route default traffic into their search engines, so that they can serve up the ads & profit from the ad dollars. Microsoft wants to put money into their bank account by serving their ads up from Bing (default IE search engine) & not into Google's pockets.
So we're not likely to see an OS API to cross-browser jQuery solution for printing anytime soon. They're not going to make that feature simply because it makes web developers lives easier. They'd only want to make that feature available, if they could find a way to make millions of dollars from it.
$(document).ready(function () {
var delays='';
$('#PrintInput').on('keyup', function () {
clearTimeout(delays);
delays = setTimeout(function () {
// do something when printing stop after 5 sec.
},5000);
});
});