2011-01-19 6 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> 

는 기본적으로이 다른 자식 창을 열고 텍스트 영역과 다른 일들이 인쇄되지 않도록 그에서 자바 스크립트 인쇄를 실행합니다 : 그것을 시도를 제공합니다.

+0

감사합니다. 그것은 저를 위해 잘 작동합니다. – Jayashri

+0

다행 :) – intellidiot

+0

Btw가 질문에 'javascript'라는 태그를 추가했습니다. – intellidiot

관련 문제