javascript - Find out when printing finishes Jquery - Stack Overflow

admin2025-04-16  0

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).

Share asked Mar 14, 2016 at 15:41 ImprfectluckImprfectluck 6846 silver badges27 bronze badges 7
  • 7 Are you sure navigating away is the cause of the problem? I would have thought that by the time the user is done with the print dialog and control returns back to the browser, the print job is already off into the printer spool? – James Thorpe Commented Mar 14, 2016 at 15:44
  • Well actually this is kinda like a label printer . This issue happens only with that printer and only when you navigate away fast. I have not experienced this issue unless I navigate fast from the page. I was sure that's how it worked before I saw this issue. – Imprfectluck Commented Mar 14, 2016 at 15:51
  • 1 Check the configuration of the printer... how does it manage the print stack, does it transfer all the data before start printing or it does it as it go? Is just an idea that could be affecting... – DIEGO CARRASCAL Commented Mar 14, 2016 at 18:06
  • 3 Watch for the window.onafterprint event: stackoverflow./questions/18325025/… – Daniel Beck Commented Mar 30, 2016 at 19:32
  • 1 Or, rather, don't do that. Poor browser support on that, it turns out (FF and IE only). Some of the answers on the question I linked to include very hacky-looking workarounds for other browsers but I wouldn't count on them... – Daniel Beck Commented Mar 30, 2016 at 19:34
 |  Show 2 more ments

3 Answers 3

Reset to default 6

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744809382a268189.html

最新回复(0)