我使用的是 Firefox 16.0.2。我想使用导入文件中定义的 css 规则打印 div 内容。当尝试在 Chrome 中打印时,它工作正常,但在 Firefox 中,打印的页面没有 css 格式。
<html>
<head>
import css here
</head>
<body>
<div id="printable"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当使用javascript打印div id=printable时,纸张结果只有HTML内容,没有CSS规则,屏幕上的结果是完美的。有没有办法让 Firefox 打印并定义所有 css,任何帮助将不胜感激。
下面添加的是我打印 div 的 javascript
function print(id)
{
var mywindow = window.open('', id, 'height=600,width=800');
var data = document.getElementById(id).innerHTML;
mywindow.document.write('<html><head><title>Print</title>');
mywindow.document.write('<link rel="stylesheet" href="../../lib/css/report/main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
Run Code Online (Sandbox Code Playgroud)
在 main.css 中,我尝试使用 @media print {#printable.....} 但它不起作用。在Javascript中,我尝试将media =“print”添加到链接标签,但它仍然对打印预览没有任何影响。
为什么不使用打印特定媒体查询呢?
@media print {
#printable {
/*Print style goes here*/
}
}
Run Code Online (Sandbox Code Playgroud)