Как убрать всплывающую опцию при печати - PullRequest
0 голосов
/ 05 ноября 2018

Я хочу удалить всплывающую опцию из этого скрипта при печати содержимого textarea, чтобы страница печати была на той же странице, что и текстовая область, потому что я добавил css, чтобы на напечатанной странице не было ссылки или даты "@page { size: auto; margin: 0mm;} "но когда он появляется на отдельной странице, он показывает ссылку и дату

<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 dir="rtl">');
        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">
@page { size: auto;  margin: 0mm; }
textarea {
direction: rtl; 
 background-color: white;
 font-size: 1em;
 font-weight: bold;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 border: 1px solid #00acee;
 resize: none;
}
input[type=button] {
    background-color: #00acee;
    border: none;
    color: white;
    padding: 16px 32px;
    text-decoration: none;
    margin: 4px 2px;
    cursor: pointer;
}
</style>
</head>

<body>
  <p>
    <TEXTAREA name="thetext" rows="20" cols="80"id="targetTextArea" placeholder="قم بنسخ و لصق الطلب لملأه و التعديل عليه و طباعته بالزر أسفله ......"></TEXTAREA>
   </p>
   <!-- print button -->
  <center> <input type="button" onclick="printTextArea()" value="طباعة"/></center>
</body>
</html>

1 Ответ

0 голосов
/ 06 ноября 2018

Это происходит потому, что вы открываете новое окно внутри printTextArea().

При открытии окна с помощью метода window.open () вы можете использовать это свойство из окна назначения для возврата сведений об исходном (родительском) окне. Вы можете прочитать больше об этом здесь, в w3schools. W3School Windower

      function printTextArea() {

        childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
        childWindow.document.open();
        childWindow.document.write('<html><head></head><body dir="rtl">');
        childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'<br/>'));
        childWindow.document.write('</body></html>');
        childWindow.print();
        childWindow.document.close();
        childWindow.close();
      }

Вместо того, чтобы открывать новое окно, вы должны выбрать текстовое поле по идентификатору и обновить его HTML, используя .innerHTML. Пример:

document.getElementById("demo").innerHTML = "Paragraph changed!";
...