2011-01-19 4 views
5

テキスト領域からテキストを印刷したい。テキストエリアからテキストを印刷するには?

私はユーザーがテキストを更新できるテキストエリアを持っています。テキストエリアからテキストを更新して印刷すると、更新されたテキストをページに印刷できます。このテキストは、テキストエリアなしの印刷ページに印刷することができます。

解決策をご提案ください。

ありがとうございました

答えて

15

私はあなたが求めているものを得たと思います。それを試してみる:

<html> 
    <head> 
    <title>Print TextArea</title> 
    <script type="text/javascript"> 
     function printTextArea() { 
     childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes'); 
     childWindow.document.open(); 
     childWindow.document.write('<html><head></head><body>'); 
     childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'<br>')); 
     childWindow.document.write('</body></html>'); 
     childWindow.print(); 
     childWindow.document.close(); 
     childWindow.close(); 
     } 
    </script> 
    </head> 
    <body> 
    <textarea rows="20" cols="50" id="targetTextArea"> 
     TextArea value... 
    </textarea> 
    <input type="button" onclick="printTextArea()" value="Print Text"/> 
    </body> 
</html> 

基本的に、これは別の子ウィンドウを開いて、テキストエリアや他のものが印刷されないようにその上でJavaScriptの印刷を実行します。

+0

ありがとう、それは私のためにうまく動作します。 – Jayashri

+0

うわー、 – intellidiot

+0

Btwさん、別のタグ 'javascript'をあなたの質問に追加しました。 – intellidiot

関連する問題