2014-09-26 47 views
1

我無法讓我的樣式表應用到我的彈出窗口。我可能錯過了簡單的東西,但我似乎無法弄清楚什麼。我使用相同鏈接的其他頁面上的CSS,它工作正常。在p將CSS應用到彈出窗口

CSS

.Code128 { 
    font-size: 50px; 
} 

JQuery的

$(document).ready(function() { 

    $('#Print').on("click", function() { 
     Popup($('#PrintDiv').html()); 
    }); 

    function Popup(data) { 
     var mywindow = window.open('', 'Print Label', 'height=400,width=600'); 
     mywindow.document.write('<html><head><title>Print Label</title>'); 

     mywindow.document.write('<link rel="stylesheet" type="text/css" href="~/Content/Fonts.css"/>'); 
     mywindow.document.write('<link rel="stylesheet" type="text/css" href="~/Content/Label.css"/>'); 

     mywindow.document.write('</head><body >'); 
     mywindow.document.write(data); 
     mywindow.document.write('</body></html>'); 

     // mywindow.print(); 
     // mywindow.close(); 
    } 
}); 

HTML

<div id="PrintDiv"> 
    <div class="Code128">BarCode</div> 
    <div class="Code128">Bar Code</div> 
</div> 
+1

發佈您的CSS或沒有人能夠提供幫助。 – Nicolas 2014-09-26 20:42:23

+0

在執行javascript之前是不是將CSS加載到DOM中? – 2014-09-26 20:43:05

+1

爲什麼不直接將CSS導入添加到HTML頁面的頂部,而是將它們附加到頁面上。因爲如果Liam是正確的,這個代碼將永遠不會工作。另外,爲什麼在你的世界中,你的html,head和body標籤附加到你的彈出窗口而不是頁面上? – Nicolas 2014-09-26 20:45:43

回答

1

你真的有 '〜' ATH?嘗試刪除它。 你可以給你的文件鏈接? 另外,如果你只想顯示文本 - 你可以使用CSS屬性「位置:絕對」,並提供必要的座標。

+0

如果您提出的問題最好是評論,而不是將其作爲回答 – 2014-09-26 20:54:06

+1

實際上刪除〜解決了問題。 – joetinger 2014-09-26 20:55:11

+0

我站好了。哈 – 2014-09-26 20:59:15