Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Вывод на печать содержимого textarea (https://javascript.ru/forum/events/48987-vyvod-na-pechat-soderzhimogo-textarea.html)

Jack-0504 24.07.2014 14:54

Вывод на печать содержимого textarea
 
Здравствуйте! Возникла необходимость распечатки посетителем содержимого textarea, особым шрифтом.
Вот что получилось:
<style><!--
@font-face {
    font-family: Allegretto Script Two; 
    src: url(fonts/Allegretto Script Two.ttf); 
   }
textarea {
    font-family: Allegretto Script Two, 'Comic Sans MS', cursive;
font-size: 30pt;}
   }--></style>
<p>
<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('Text').value.replace(/\n/gi,'<br>'));
        childWindow.document.write('</body></html>');
        childWindow.print();
        childWindow.document.close();
        childWindow.close();
      }
    </script>
</p>
<p><textarea id="Text" cols="10" name="propisi" rows="10" onfocus="this.value=''; setbg('#e5fff3');" onblur="setbg('white')"></textarea></p>
<p><input onclick="printTextArea()" type="button" value="Печать" /></p>

Шрифт подключается, в самой форме отображается корректно. Но при выводе на печать он меняется на стандартный. Т.е. на бумагу выходит обычный шрифт.
Как решить проблему, подскажите.

Маэстро 24.07.2014 15:53

<style><!--
@font-face {
    font-family: Allegretto Script Two; 
    src: url(fonts/Allegretto Script Two.ttf); 
   }
textarea {
    font-family: Allegretto Script Two, 'Comic Sans MS', cursive;
font-size: 30pt;}
   }--></style>
<p>
<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.body.style.fontFamily = 'Comic Sans MS';
        childWindow.document.body.style.fontSize = '32pt';
        //////////////////////////////////////////////// 
        
        childWindow.document.write(document.getElementById('Text').value.replace(/\n/gi,'<br>'));
        childWindow.document.write('</body></html>');
        childWindow.print();
        childWindow.document.close();
        childWindow.close();
      }
    </script>
</p>
<p><textarea id="Text" cols="10" name="propisi" rows="10" onfocus="this.value=''; setbg('#e5fff3');" onblur="setbg('white')"></textarea></p>
<p><input onclick="printTextArea()" type="button" value="Печать" /></p>

Jack-0504 24.07.2014 16:13

Спасибо, Маэстро!
Теперь работает.


Часовой пояс GMT +3, время: 15:36.