简体   繁体   中英

How to remove pop-up option in printing

I want to remove pop-up option from this script while printing the content of textarea so the print page will be in same page of the textarea because i added css so the printed page wont have link or the date "@page { size: auto; margin: 0mm; }" but when it pop-up in seperate page it shows link and date

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

This is happening because you are opening a new Window inside printTextArea() .

When opening a window with the window.open() method, you can use this property from the destination window to return details of the source (parent) window. You can read more about it here at w3schools. W3School Window Opener

      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();
      }

In stead of opening the new window, you should be selecting your textarea by id and updating it's html using .innerHTML . Ex:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM