如何查看打印结果 RTL
How to view Print result RTL
当我在 textarea 中打印文本时,它显示 LTR 而我的文本是 RTL 那么我该如何解决这个问题,以便文本显示为左、右或居中,我在复制文本区域时遇到另一个问题它向右对齐,但有时我在中间有某些单词,它们在文本编辑器区域向右移动
<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>
只需给 child 的主体一个值为 rtl 的方向属性,因此只需更改此行:
childWindow.document.write('<html><head></head><body>');
对此:
childWindow.document.write('<html><head></head><body dir="rtl">');
当我在 textarea 中打印文本时,它显示 LTR 而我的文本是 RTL 那么我该如何解决这个问题,以便文本显示为左、右或居中,我在复制文本区域时遇到另一个问题它向右对齐,但有时我在中间有某些单词,它们在文本编辑器区域向右移动
<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>
只需给 child 的主体一个值为 rtl 的方向属性,因此只需更改此行:
childWindow.document.write('<html><head></head><body>');
对此:
childWindow.document.write('<html><head></head><body dir="rtl">');