2017-06-20 5 views
0

私はWebアプリケーション(java、jsp、js)に、画面の選択された領域からHTMLを取り出し、 iframeを 'iFramePrint'と呼び、それを印刷します。最近のWindows UpdateのためにiFrame印刷用の交換が必要

<iframe name="iFramePrint" frameborder="0" src="Blank.jsp" marginheight="0" marginwidth="0" width="0" height="0"></iframe> 

function doPrint() { 
    if (window.frames['iFramePrint'].document.body) { 

     var str = '<B>'+'<h1>' + document.getElementById('tdMainTitle').innerHTML +'</h1>'+'</B>'; 
     str += '<BR>'; 
     etc. 
     str=str.replace(/BORDER=0/g ,"border=1"); 
     window.frames['iFramePrint'].document.body.innerHTML = str; 
     window.frames['iFramePrint'].focus(); 
     window.frames['iFramePrint'].print(); 
    } 
} 

これは長い間うまくいきましたが、最近のWindows Updateのためにコードは機能しなくなりました。下記参照。

https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/cannot-print-single-frames-iframes-popups-after/e431c6e1-5f27-4bef-93ce-d8d9ae23a477

Iは、好ましくは、Microsoftがこの問題を解決するのを待つ必要はありません - それはしばらくの間である可能性があります。 KB4022715をアンインストールするようクライアントに依頼したくないのですが(ナレッジベース番号はWindowsのバージョンによって異なりますが、7月のセキュリティ更新プログラムのロールアップは今月リリース)、問題は解決します。

私はこれを解決する方法を持っています.HTMLを使ってPDFに変換し、PDFをダウンロードできるようにしました。これは間違いなく実行可能です。 Converting HTML files to PDFを参照してください。より良い方法があるかどうかは疑問です。

答えて

0

私が今までに見つけた最良の解決策は、iFramePrintを新しいウィンドウで置き換えることです。

function doPrint() { 
     var str = '<B>'+'<h1>' + document.getElementById('tdMainTitle').innerHTML +'</h1>'+'</B>'; 
     str += '<BR>'; 
     etc. 
     str=str.replace(/BORDER=0/g ,"border=1"); 
     w=window.open(); 
     w.document.write('<html><head><title>Printout</title>'); 
     w.document.write('</head><body >'); 
     w.document.write(str); 
     w.document.write('</body></html>'); 
     w.document.close(); 
     w.focus(); 
     w.print(); 
     w.close(); 
} 

window.print() not working in IEに@pratikすると、おそらく、新しいウィンドウを開かずにトリックを行いますが、他の答えがありますHow to print HTML content on click of a button, but not the page? に@jaayに感謝します。

関連する問題