google chrome print preview does not load the page the first time

前端 未结 4 1308
刺人心
刺人心 2021-01-12 17:51

I\'m trying to print a page using this code



    

        
4条回答
  •  自闭症患者
    2021-01-12 18:11

    You need to put delay before print. There is a native defect in chrome.

    Code would as under :-

    function PrintDiv(data) {
        var mywindow = window.open();
        var is_chrome = Boolean(mywindow.chrome);
        mywindow.document.write(data);
    
       if (is_chrome) {
         setTimeout(function() { // wait until all resources loaded 
            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10
            mywindow.print(); // change window to winPrint
            mywindow.close(); // change window to winPrint
         }, 250);
       } else {
            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10
    
            mywindow.print();
            mywindow.close();
       }
    
        return true;
    }
    

提交回复
热议问题