Jak vytisknout text z textové oblasti?

Chci vytisknout text z textové oblasti.

Mám textovou oblast, jejíž text může uživatel aktualizovat. Když uživatel aktualizuje text z textové oblasti a poté vytiskne, aktualizovaný text lze vytisknout na stránku. A tento text lze vytisknout na tiskovou stránku bez textové oblasti.

Navrhněte jakékoli řešení.

Díky

Odpověď

Myslím, že jsem dostal, o co žádáte. Zkuste to:

<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>

V podstatě se tím otevře další podřízené okno a spustí se v něm tisk javascriptu, aby se textová oblast a další věci nevytiskly.