У меня есть этот код javascript для печати содержимого div.
function PrintElem()
{
var mywindow = window.open('', 'PRINT', 'height=600,width=800');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('<style type="text/css">' + @media print {
.no_print{ display:none;}
.fav_thumb{width:50%; height:50%; float:left}
} + '</style>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h2>' + document.title + '</h2>');
mywindow.document.write(document.getElementById("favorite_items").innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}
Как я могу написать некоторый print css для этого нового окна, который открывается javascript?
Вариант №1 - встроенные стили могут быть применимы к вашей цели.
Этот абзац HTML-пример элемента, использующего встроенные стили, был показан в предыдущей ссылке.
<p style="color:blue;font-size:46px;">
I'm a big blue, <strong>strong</strong> paragraph
</p>
Вариант № 2 - определения внутреннего стиля
Вариант № 3 - Файлы внешнего стиля
Стиль HTML с CSS- ссылкой охватывает все три (3) варианта.
@media
), должен быть заключен в кавычки.