2016-04-24 14 views
0

htmlレポートページで印刷操作を実行しようとしています。私はHTMLページのいくつかの部分だけを「PDFを書き出す」ボタンのクリックでPDFプリントとして欲しい。 新しいiframeに必要なコンテンツを配置し、ボタンをクリックしてiframeを印刷しました。そしてその完璧な作業。ここでiframeの内容を表示するjqueryがリモートサーバーで動作しない

は私の本番サーバー(Windows Server 2012)にコードを移動したときに私のコード

$('#btnprint').on('click',function(){ 
 
     $('#print-iframe').contents().find('html').html($('#divprintheader').html() + $('#divreport').html()); 
 

 
    $("#print-iframe").get(0).contentWindow.print(); 
 
});
<table id="tblentrancereport" class="reporttable" style="width: 100%"> 
 
           <thead> 
 
           <tr> 
 
            <th>Name</th> 
 
            <th>Count</th> 
 
            <th>Amount</th> 
 
           </tr> 
 

 
           </thead> 
 
           <tbody></tbody> 
 
          </table> 
 
<div id="divprintheader" style="display: none"> 
 

 
        From : <span id="spnfromdate"></span> &nbsp;&nbsp;&nbsp;&nbsp; To : <span id="spntodate"></span> 
 
        <div id="divprintfilter"> 
 
         Filtered By : <span id="spnfilteredby"></span> 
 
         <div id="divcontentbelongto"> 
 

 
         </div> 
 
        </div> 
 

 
       </div> 
 

 
<button id="btnprint">Export PDF</button> 
 
       <iframe name="print_frame" id="print-iframe" width="0" height="0" frameborder="0" src="about:blank"></iframe>

は、残念ながら、私は(プリントウィンドウが来ているiframe内のコンテンツを取得していない午前です)。 iframeには、動的に形成された新しいコンテンツが埋め込まれています(ページ要素の検査時に表示されることがあります)。誰かが私が間違っているところを見つけ出すことはできますか?ここで

はスクリーンショットです

Image 1私は自分のサーバーにしようとしたとき、私は私のlocalhostの

Image 2印刷にしようとした印刷を

UPDATE そして奇妙なことは、ときにI要素を点検し、開発者用ツールの内容を展開して、[Export PDF]ボタンをクリックしてください:O

がエラーをトレースすることはできません:(

+1

'sandbox ="で 'src'属性を試して削除することがあります。allow-forms allow-modals allow-popups allow-same-origin allowスクリプト" –

+0

@MichaelSchwartzお返事ありがとう!しかし、働いていない.. :( – NCA

+0

そして、奇妙なことは、開発者のツールで要素を調べて内容を展開してから、「PDFを書き出す」ボタンをクリックすると、その機能が働くことです。 エラーをトレースできません:( – NCA

答えて

0

<head> 
 
<script type="text/javascript"> 
 
function ClickHereToPrint(){ 
 
    try{ 
 
     var oIframe = document.getElementById('ifrmPrint'); 
 
     var oContent = document.getElementById('divToPrint').innerHTML; 
 
     var oDoc = (oIframe.contentWindow || oIframe.contentDocument); 
 
     if (oDoc.document) oDoc = oDoc.document; 
 
\t \t oDoc.write("<html><head><title>title</title>"); 
 
\t \t oDoc.write("</head><body onload='this.focus(); this.print();'>"); 
 
\t \t oDoc.write(oContent + "</body></html>"); \t  
 
\t \t oDoc.close(); \t  
 
    } 
 
    catch(e){ 
 
\t  self.print(); 
 
    } 
 
} 
 
</script> 
 
</head> 
 

 

 
<body> 
 

 
<a onclick="ClickHereToPrint();">Print</a> 
 

 
\t <iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe> 
 
\t <div id="divToPrint"> 
 
\t \t content 
 
\t </div> 
 
</body>

私は問題を把握できなかったものの、このソリューションは完璧に動作します。ありがとう!!

関連する問題