2016-03-28 14 views
-2

このスクリプトを試しましたが、印刷中にスタイルが正しく読み取られないと、誰でも問題を把握できますか?Cssは印刷コードで読み取られません

<script type="text/javascript"> 
    $(function() { 
     $("#btnPrint").click(function() { 
      var contents = $("#dvContents").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="style.css" rel="stylesheet" type="text/css" />'); 
      //frameDoc.document.write('<link href="bootstrap.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> 
+0

は、あなたのスタイルシートが@media印刷が含まれています.....このようなルート・パスに応じてそれを書きますか? –

答えて

0

問題がCSSファイルパスである可能性があります。

<link rel="stylesheet" href="../css/style.css" /> 
+0

パスが正しいです。メインページに使用したものと同じです。問題は印刷ページにあります。特定のdivをUIで印刷したいのですが –

関連する問題