当用户点击打印按钮时,我有这个JS功能。javascript window.print CSS @media不能正常工作
<script>
function printDiv()
{
var printer = window.open('','','width=300,height=300');
printer.document.open("text/html");
printer.document.write(document.getElementById('news_contents').innerHTML);
printer.print();
}
</script>
而且我包括CSS作为
@media print {
#news_content {
color: #666;
font-size: 12px;
font-family: Arial,Helvetica,sans-serif;
}
}
然而,当用户打印时,CSS并不适用。我检查了HTML标题,CSS脚本确实存在。为什么它不起作用? 当用户从Mac打印时,内容区域中的图像缩小并变小。无论如何,我可以拥有完全一样的网站?
在此先感谢。
希望它有帮助http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/ –
嗨@SantiagoRebella感谢您的链接。在我的编码中似乎没有任何错误,不知道为什么不应用CSS。 – Sylph