简体   繁体   中英

How to add delay in opening Print Dialog untill page or PDF fully loaded:JS

I have created the print function that is working fine in chrome but in firefox its printing blank page. because print dialog comes before the PDF fully loaded so when we hit "ok" its perform the action to print. Question is how to add delay to print dialog to appear after PDF fully Loaded.

Here is My Code:

   function printPDF(url) 
    {

    var w = window.open(url);

   var FIREFOX = /Firefox/i.test(navigator.userAgent);
    if (FIREFOX) {
    if (typeof w.print === 'undefined') {    
    setTimeout(function(){printPDF(url);},3000);
    } else {
     w.print();
    }

     }else{

      w.print();
       }
   }

I suspect you are getting a blank page because your window 'w' contains no printable text. The PDF is opened via a plugin which falls outside your w.print(); request.

var w = window.open(url);
w.print();

I suspect your options are limited - the plugin opens the PDF - a different plugin could have a different js library so a universal solution might not be available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM