printing div content with css applied

后端 未结 8 822
北海茫月
北海茫月 2020-12-28 17:13

I am working on a project and I want to print div content.The code which I am using is fulfilling my requirements,but I am getting simple output without Css applied to it an

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 17:27

    I combined and had this working perfectly:

    function PrintElem(elem)
    {
        var mywindow = window.open('', 'PRINT', 'height=400,width=600');
    
        mywindow.document.write('');
        mywindow.document.write("")
        mywindow.document.write('');
        mywindow.document.write(document.getElementById('printit').innerHTML);
        mywindow.document.write('');
    
        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10*/
    
    
        setTimeout(function () {
        mywindow.print();
        mywindow.close();
        }, 1000)
        return true;
    }
    

提交回复
热议问题