How to view Print result RTL

2783 views javascript
10

When i print text in textarea it shows LTR and my text is RTL so how can i fix this problem so the text will show up like is it left or right or center and i have another problem when i copy text area it aligns to right but sometime i have certain words in the center and they move to right in the text editor area

<html ">
<head>
<title></title>
<!-- script print button -->
 <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>
<style type="text/css">
textarea {
direction: rtl; 
 background-color: white;
 font-size: 1em;
 font-weight: bold;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 border: 1px solid black;
}
</style>
</head>

<body>
  <p>
    <TEXTAREA name="thetext" rows="20" cols="80"id="targetTextArea" ></TEXTAREA>
   </p>
   <!-- print button -->
  <center> <input type="button" onclick="printTextArea()" value="?????"/></center>
</body>
</html>

answered question

1 Answer

8

Just give the child's body a direction attribute with the value rtl, so just change this line:

childWindow.document.write('<html><head></head><body>');

to this:

childWindow.document.write('<html><head></head><body direction="rtl">');

posted this

Have an answer?

JD

Please login first before posting an answer.