[英]not able to add the css file to html while print
I'm trying to add the css file to the HTML content while printing it. 我正在尝试在打印时将css文件添加到HTML内容。 But the css file is not getting added.
但是没有添加css文件。 I'm getting the output without the CSS.
我得到的输出没有CSS。 Can anyone please help me...
谁能帮帮我吗...
Here is my code 这是我的代码
<html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> <script type="text/javascript"> function PrintElem(elem) { Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'mydiv', 'height=700,width=1200'); mywindow.document.write('<html><head><title></title>'); mywindow.document.write('<link rel="stylesheet" href="print.css" type="text/css" media="print"/>'); mywindow.document.write('</head><body >'); mywindow.document.write(data); mywindow.document.write('</body></html>'); mywindow.document.close(); // necessary for IE >= 10 mywindow.focus(); // necessary for IE >= 10 mywindow.print(); mywindow.close(); return true; } </script> </head> <body> <div id="mydiv"> This will be printed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a quam at nibh adipiscing interdum. Nulla vitae accumsan ante. </div> <div> This will not be printed. </div> <div id="anotherdiv"> Nor will this. </div> <input type="button" value="Print Div" onclick="PrintElem('#mydiv')" /> </body> </html>
and this is my CSS file 'print.css' 这是我的CSS文件“ print.css”
@media print { #mydiv { border: 10px solid !important; color: red; font-size:20px !important; } }
Figured out where you are making problem: 找出问题所在:
Solution please pass entire div rather then just div.html() into Popup funciton 解决方案,请将整个div而不是仅将div.html()传递到Popup函数中
try something like this or try other way to do so 尝试类似的方法或尝试其他方法
function PrintElem(elem)
{
Popup($(elem)); // send div not html only
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.