2016-04-24 13 views
1

私はwindow.print()を使用しています。 Webページ上の印刷固有の部分については、そのFirefoxのブラウザで動作しているが、私は空白の印刷プレビューを私に見せてくれるChromeで正しく動作しません。cssが動作しないクロムのprint div

<script type="text/javascript"> 
    function printDiv() { 
    var divToPrint = document.getElementById('table'); 
    var htmlToPrint = '' + 
     '<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />'+ 
     '<link href="../dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />'; 
     $(document).ready(function() { 
    $('#customers').dataTable(); 
     }); 
    htmlToPrint += divToPrint.outerHTML; 
    newWin = window.open(""); 
    newWin.document.write(htmlToPrint); 
    newWin.print(); 
    newWin.close(); 
} 
    </script> 

私のために、次のコードの作業を上記のコードはまた、クロムに罰金働いていたが、最後の15日から、それはクロムで働いていないが、Firefoxの

+0

多分これがありますクロム50バージョンの問題、私も新しいバージョンに問題があった。あなたのバージョンは何ですか? –

+0

マイクロームバージョン50.0.2661.87 m –

答えて

1

で働い罰金

<script type="text/javascript"> 
     $(function() { 
      $("#btnPrint").click(function() { 
       var contents = $("#table").html(); 
       var frame1 = $('<iframe />'); 
       frame1[0].name = "frame1"; 
       frame1.css({ "position": "absolute", "top": "-1000000px" }); 
       $("body").append(frame1); 
       var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument; 
       frameDoc.document.open(); 
       //Create a new HTML document. 
       frameDoc.document.write('<html><head><title>DIV Contents</title>'); 
       frameDoc.document.write('</head><body>'); 
       //Append the external CSS file. 
       frameDoc.document.write('<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />'); 
       frameDoc.document.write('<link href="../dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />'); 
       //Append the DIV contents. 
       frameDoc.document.write(contents); 
       frameDoc.document.write('</body></html>'); 
       frameDoc.document.close(); 
       setTimeout(function() { 
        window.frames["frame1"].focus(); 
        window.frames["frame1"].print(); 
        frame1.remove(); 
       }, 500); 
      }); 
     }); 
    </script>