简体   繁体   English

如何增加打开打印对话框直到页面或PDF完全加载的延迟:JS

[英]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. 我已经创建了在chrome中可以正常工作的打印功能,但是在Firefox中却可以打印空白页。 because print dialog comes before the PDF fully loaded so when we hit "ok" its perform the action to print. 因为打印对话框是在PDF完全加载之前出现的,所以当我们单击“确定”时,将执行打印操作。 Question is how to add delay to print dialog to appear after PDF fully Loaded. 问题是如何添加延迟以在PDF完全加载后出现打印对话框。

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. 我怀疑您正在获取空白页,因为窗口“ w”不包含可打印文本。 The PDF is opened via a plugin which falls outside your w.print(); PDF文件是通过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. 我怀疑您的选择是有限的-插件打开PDF-不同的插件可能具有不同的js库,因此可能无法使用通用解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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