簡體   English   中英

如何將CSS文件添加到print()

[英]How to add CSS file to print()

我已經看到了幾個答案,但似乎對我不起作用。 我有一個打印網格的功能,但是CSS不會移過來(除非我手動添加樣式)。 如何添加CSS文件? 我試過了:

$("#btn").click(function (e) {
        var divToPrint = document.getElementById("expertiseTable");
        newWin = window.open("");
        //var myStyle = '<link rel="stylesheet" type="text/css" href="http://localhost:59840/Content/Site.css" />';
        newWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="http://localhost:59840/Content/Site.css" /></head><body onload="window.print()">' + divToPrint.innerHTML + '</body></html>');
        newWin.print();
});

http:// localhost:59840 / Content / Site.css放到瀏覽器中會彈出我的CSS文件,因此我在那里知道它,但是當我嘗試打印時似乎找不到它。

您是否嘗試過類似的方法,

newWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="http://localhost:59840/Content/Site.css" media="print" /></head><body onload="window.print()">' + divToPrint.innerHTML + '</body></html>');

這里找到。

我放置了media="print"屬性。

還有@media print用法選項,

<style type="text/css">
    @media print{
        .aClass { display: none; }
    }
</style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM